These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

I need a date field to display the current year when user enters only month and day

artstar
Registered: Jan 24 2011
Posts: 2

How do I create and format a date field so it will automatically supply the current year if the user only enters the month and day?
 
Example: If user enters "2/4" the date should display "2/4/2011"

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
This can be done with a FormCalc script in the exit:Event of the date field.

  1. ; Get current year
  2. var Year = Num2Date(date(), "YYYY")
  3. ; Get input
  4. var Input = this.formattedValue
  5.  
  6. ; If input has less than 7 characters (23.07. = 6 characters) then add the current year to complete the date
  7. if (Len(Input) < 7) then
  8. var Output = Concat(Input, Year)
  9. $ = Num2Date(Date2Num(Output, "DD.MM.YYYY", "DD.MM.YYYY"))
  10. else
  11. $.rawValue
  12. endif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

artstar
Registered: Jan 24 2011
Posts: 2
I created a new document and inserted a single Date/Time Field. I copied and pasted the FormCalc script into the exitEvent of the date field. I saved the sheet and then tried it out. The Date/Time Field still does not show the year when I enter a date such as 5/25.

I also notice that there is an asterisk (*) after the word "exit" in the "Show:" dropbox at the top of the script editor.

Here is what my code looks like:

form1.#subform[0].DateTimeField1::exit - (FormCalc, client)
; Get current year
var Year = Num2Date(date(), "YYYY")
; Get input
var Input = this.formattedValue

; If input has less than 7 characters (23.07. = 6 characters) then add the current year to complete the date
if (Len(Input) < 7) then
var Output = Concat(Input, Year)
$ = Num2Date(Date2Num(Output, "DD.MM.YYYY", "DD.MM.YYYY"))
else
$.rawValue
endif

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
You may have to change the display patterns of my example ("DD.MM.YYYY") in that way you would like to display the dates in your country.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs