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

Date Calculations in LiveCycle

scooterinwi
Registered: Oct 2 2007
Posts: 2

Please excuse the beginner level questions but...

I would like to do something that I thought would be very simple in LiveCycle:

I have a drop-down called "Shipment Method"
I have a date field called "Order Date"

I have another date field "Expected Date" (see where I'm going with this?)

If the shipment method field equals ground, the the expected date field should equal the order date field plus 5 days.

IE:
Shipment Method = Ground
Order Date = 10/5/2007
Expected Date = 10/10/2007

I have done a lot of searching but can only find ways to calculate number of days. Any ideas?

Thanks all!

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
If you want x number of days added to a date, is not that adding days?

You need to use the "Date2Num()" FormCalc function to convert the order date to days (actually the number of days since Jan 1, 1990). If you add 5 days to that value you will now have the number of days form for the order date plus 5 days from Jan 1, 1990. Now you can use the "Num2Date()" function to convert the new number of days since Jan 1, 1990 back to a date.

George Kaiser

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
With careful planning of the "On" and "Off" values, one can use a FormCalc calculation like:

// FormCalc calculation script for the DeliverDate
// debugging code
xfa.host.messageBox(Concat("The input date is: ", OrderDate.formattedValue,
"
InputDate number: ", Date2Num(OrderDate.formattedValue, "MMM D, YYYY"),
"
Ground value: ", Ground,
"
DeliveryDate number: ", Date2Num(OrderDate.formattedValue, "MMM D, YYYY") + Ground,
"
DeliveryDate: ", Num2Date( Date2Num(OrderDate.formattedValue, "MMM D, YYYY") + Ground )), "Debugging", 3)
// end debugging

if (HasValue(OrderDate) AND Ground EQ 5) then
// if OrderDate not empty and Ground is equal to 5 (On = 5 / Off = 0) compute delivery date
Num2Date( Date2Num(OrderDate.formattedValue, "MMM D, YYYY") + Ground )
else
// no OrderDate value then clear field
""
endif

You can remove the debbuggins statements for the final form, but they should show you how the days are added. Using JavaScript, one can add not only days but months and years or deal with the full date and time computations.

George Kaiser