Have you figured out how to do this? I'm working on a similar issue.
Try this site here for a reference: http://eslifeline.wordpress.com/2008/09/26/date-manipulation/
The following was the use case. A form has 2 TextFields Start_Date and End_date
User enters a certain date in the Start_Date text field for example 09/24/08 (MM/DD/YY)
The End_Date should add 90 days to the Start_date and populate the End_Date
The following script would do that
var current = Date2Num(Start_Date.rawValue, “MM/DD/YY”)
var future = current+90
var newDate = Num2Date(future,”MM/DD/YY”)
form1.#subform.End_Date.rawValue = newDate
Validating End Date is later than Start Date
var diff = Date2Num(EndingDate.rawValue, “YYYY-MM-DD”) – Date2Num(StartingDate.rawValue, “YYYY-MM-DD”)
if (diff > 0) then
xfa.host.messageBox(“The End date is later than start date”)
xfa.host.messageBox(“PLEASE CHECK….The End date is before the start date”)
Just one additional tip to the script above.
You always should refer to the formattedValue than the rawValue, because the the formattedValue is in the format you'll see in the date field while the rawValue may be completely diffent.
This is because of the display and edit patterns you can add to fields.
So better is the following script:
var current = Date2Num(Start_Date.formattedValue, “MM/DD/YY”) ...