-
1. Re: Add 180 days to a new date field
Jono Moore Feb 15, 2012 12:03 PM (in response to keithreim)1 person found this helpfulOn the Exit event of the date field you can do this:
var beginDate = Date2Num($,"YYYY-MM-DD")
endDateField = Num2Date(beginDate + 180, "YYYY-MM-DD")
Make the endDateField a text field, not a date field - you're specifying the date format in the Num2Date() code (I've got it as "YYYY-MM-DD" but you can do different variations).
You'll want to set up some Display, Edit and Validation patterns on the date field so you get a proper date. The Display pattern is how the date looks on screen, the Edit pattern is for how people can enter the data (you can have more than on Edit pattern to allow some flexibility) and the date has to pass the Validation pattern to be valid. It's a good idea to specify the date format you want in the field caption and in a tooltip so form fillers know how to enter the date properly if they don't use the calendar popup.
-
2. Re: Add 180 days to a new date field
keithreim Feb 15, 2012 12:22 PM (in response to Jono Moore)Thank you - that worked great!
-
3. Re: Add 180 days to a new date field
Marti1478 May 2, 2012 9:11 AM (in response to Jono Moore)I tried using your formcalc script for adding 180 days. However, everytime any date is picked the end text field is returning Jun 19 1900. Any thoughts?
-
4. Re: Add 180 days to a new date field
keithreim May 2, 2012 9:36 AM (in response to Marti1478)Can you send me your code? It sounds like a date formatting issue.
Keith
-
5. Re: Add 180 days to a new date field
Marti1478 May 2, 2012 10:06 AM (in response to keithreim)I pretty much used exactly what you had provided. I named my date pickler field DateOne (it is represented by the $) I named the text field endDateField. This runs at the client.
Then, I set up the form calc script on the exit event to be this:
var beginDate = Date2Num($, "MM/DD/YYYY")
endDateField = Num2Date(beginDate + 180, "MM/DD/YYYY")
I wanted the dates to display like 01/01/2012
I set up the patterns for data and display on the date field using the select type list and chose the 04/01/2007 option in LiveCycle ES2 which returned this pattern: date{MM/DD/YYYY}
-
6. Re: Add 180 days to a new date field
keithreim May 2, 2012 10:27 AM (in response to Marti1478)Make one change to the var line as shown below
var Part1Date = Date2Num($,"YYYY-MM-DD")
Your date should still show the way you prefer in both boxes, but make sure you add a note on the form to use the date selection box .
-
7. Re: Add 180 days to a new date field
keithreim May 2, 2012 10:36 AM (in response to Marti1478)Should be
var beginDate = Date2Num($, "YYYY-MM-DD")
-
-
9. Re: Add 180 days to a new date field
keithreim May 2, 2012 12:26 PM (in response to Marti1478)Ok, for the field you are entering the date in – is the object name “beginDate”, or is it DateOne as it appears? If the name of the object is DateOne, change the var line to:
var DateOne = Date2Num($,"YYYY-MM-DD")
Or rename the object to beginDate – either way should work.
-
10. Re: Add 180 days to a new date field
Jono Moore May 2, 2012 12:29 PM (in response to Marti1478)Try moving your code to the Exit event of the date field.
-
11. Re: Add 180 days to a new date field
Marti1478 May 2, 2012 12:48 PM (in response to keithreim)That was it - simple thing i missed, I renamed the beginDate for DateOne. Working now! thanks.
-
12. Re: Add 180 days to a new date field
Jono Moore May 2, 2012 1:11 PM (in response to keithreim)Ok, for the field you are entering the date in – is the object name “beginDate”, or is it DateOne as it appears? If the name of the object is DateOne, change the var line to:
var DateOne = Date2Num($,"YYYY-MM-DD")
Or rename the object to beginDate – either way should work.
The variable name has no bearing on the name of the object, you could call it Fred if you wanted to.
But the variable name has to match in the two expressions.
var Fred = Date2Num($, "MM/DD/YYYY")
endDateField = Num2Date(Fred + 180, "MM/DD/YYYY")
I did encounter the problem that Marti was having with the code on the Change event though. So I'm not sure what was going on now.
-
13. Re: Add 180 days to a new date field
Leslieyosbe Jan 8, 2013 11:02 AM (in response to Jono Moore)Hello! what I'm I doing wrong??
I think I did everything as outlined above but I'm still getting 06/29/1900 on my endDateField. Please help me find the error
var beginDate = Date2Num($, "MM/DD/YYYY")
endDateField = Num2Date(beginDate + 180, "MM/DD/YYYY")
I named my fields according to the script just to make sure I'd work but it didn't - thank you!!!
-
14. Re: Add 180 days to a new date field
Jono Moore Jan 8, 2013 11:34 AM (in response to Leslieyosbe)Change the pattern in the first line to "YYYY-MM-DD". For some reason I've found the date math works better when using the ISO date standard. So this converts from whatever date pattern you are using to the standard.
var beginDate = Date2Num($, "YYYY-MM-DD")
-
15. Re: Add 180 days to a new date field
Leslieyosbe Jan 8, 2013 11:45 AM (in response to Jono Moore) -
16. Re: Add 180 days to a new date field
Jono Moore Jan 8, 2013 12:18 PM (in response to Leslieyosbe)I think I see what's going on, change your "endDateField" to a date/time field and set its patterns to the way you want the date displayed.
The original script was meant for a date field to pick the date and a text field to put the new date in. Because you are trying to do it in one field it needs to be a date field.
-
17. Re: Add 180 days to a new date field
Leslieyosbe Jan 9, 2013 9:24 AM (in response to Jono Moore)Hi Jono,
I actualy do have the date field to pick a date (see first picture "Date" next to "Invoice number") which I named "beginDate" and the "endDateField" text field to show the future date.
I know this is weird but is still not working, any other suggestions?
thank you again, I really apreciate your help!!!
-
18. Re: Add 180 days to a new date field
Jono Moore Jan 9, 2013 9:41 AM (in response to Leslieyosbe)Ok, so the original script then should be on the exit event of the Date field, not on the text field.
And I'd call it something other than "beginDate", to be on the safe side, as that is the name of the variable being used in the script.
-
19. Re: Add 180 days to a new date field
Leslieyosbe Jan 9, 2013 9:49 AM (in response to Jono Moore)Yay!!!!! It worked!!! Thank you so very much!!!!!
I wish you a very Happy 2013!!