Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

System Date Calculation

Not applicable
Good day and thanks in advance for your help. I am new to Adobe users forums as of Yesterday 6-24-08. I am also new to the designing of these forms but I think I am going to like it. My question is: Can I calculate the difference between 2 dates and get a results of make the finish date be 30 days later than the original date.



Example in excel, for instance: Cells A1 & B1 are dates fields and in A1 I use todays date 6/25/08 and in B1 put this coded =A1+29 then B1 results will be show the date of 7/24/08 which is 30 days out.



Is this possible?
16 Replies
gkaiseril
Level 7
Level 7
Yes, one can use FormCalc functions or the JavaScript date time object.



FormCalc has a "Date2Num()" function to get the number of days since the Epoch date and the "Num2Date()" function to convert the number days since the Epoch date to a date string.



JavaScirpt is more complex and computes dates based on the milliseconds from the Epoch date.



There is more information about the FormCalc date and time functions in the Scripting references provided with LiveCycle Designer.
Not applicable
Thank you so very much for your immediate response. I have seem some example in the forum, but I can't seem to get it to work. I think I have placed them in the right place on the form here is what I have done thus far:



if (Date1.rawValue ne null) then

Num2Date(Date2Num(Date1.rawValue, "MM/DD/YYYY") + 29, "MM/DD/YYYY")

else

null

endif



Is there anyting else I need to add to make this code work.



Thanks for your help.
gkaiseril
Level 7
Level 7
Have you tried the "formattedValue" and make sure the date string is formatted in the same manner as your parameter srting.
Not applicable
I am putting the code in the validation script message I was just checking the date string on the binding tab to make sure they were the same. I don't see that pattern in the drop down box, so I just typed it and it stayed in place. I am using the date/time pick calendar, does that make a difference why it might not be working?
gkaiseril
Level 7
Level 7
The code should be in the Calculation event for the B1 field. You really need to use the "formattedValue" as picture in the display field option since there are too many data entry variations for dates.
Not applicable
Sorry I am so confusing, this is not in excel, the form is created in adobe designer 7.0 and I will try formatedValue as soon and I can research it and see what's is all about. Thanks for all your help, I will keep you informed when I resolved this issue.
Not applicable
Good Morning GEO



Ok if finally figure out where to insert the code, but for some reason it is giving me a 1900 date in the date 2 field. here is my code, can you tell me what I am doing wrong;



if (Date2.formattedValue ne null) then

Num2Date(Date2Num(Date2.formattedValue, "MM/DD/YYYY") + 29, "MM/DD/YYYY")

else

null

endif
Not applicable
I have tried formatedValue and rawValue and neither of them work, Please tell me what is wrong. It give me a date of 1/29/1900,in the Date2 field, when I select the current date from a calendar when I use the below code:



If(Date1.rawValue ne null) then

Num2Date(Date2Num(Date1.rawValue, "MM/DD/YYYY") + 29, "MM/DD/YYYY")

else

null

endif



Thanks to anyone who response
Not applicable
Thanks to all, I finally got it figure out. It took me a moment to understand what I was doing, but I am one of those folks, that will never take no as a final answer. The code for date/time from a calendar do just what I wanted it to do. Count 30 days from the beginning date to the end date.



Thanks for putting on the right path.
Not applicable
Hi Brenda



I am trying to do what u are doing. I want my second date to automatically generate in the Date2 field 90 days after Date1. what do i have to do. im stuck. i keep on getting 1900 date just like you did by using the code above. im no programmer and very new to formcalc. what code did u use to get the job done. please please help!!!!
gkaiseril
Level 7
Level 7
It sounds like you are not getting the correct number of days from the "Date2Num()" function. You must use the "formattedValue" for the required date string parameter and provide the optional format string with the correct picture format for the field value being passed to the "Date2Num()" function. If you do not the function returns 0.
Not applicable
Hi I have 2 date fields and a total field. I want the Total field to calculate the number of days between the dates but make sure it takes th efirst date as one day. i figured out the formula to get that to work, BUT I dont want the 1 to show on the form before the start date is selected. Can you help?



IsoDate2Num(EndDate)-IsoDate2Num(StartDate)+1
Not applicable
try this lucy



if (HasValue(Date2)) then

// if Date2 not empty compute Total

IsoDate2Num(EndDate)-IsoDate2Num(StartDate)+1

else

// no Date2 value then clear field

""

endif



let me know if it helps
Not applicable
I have no idea how i figured it out, but I did. I put this code in and it took:



If(StartDate.rawValue ne null)then

IsoDate2Num(EndDate)-IsoDate2Num(StartDate)+1

else

DaysAttending=0



seems to be calculating after the start date is choosen now. Thank you so much for your help. I'm sure I'll find another question along the way of building this form.
gkaiseril
Level 7
Level 7
See Difference between Date2Num and IsoDate2Num functions?

, http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=15494 . For some code and examples of entered date and the date conversion with different format parameter values.



There is a lot that has to be correct for converting a date string to the number of days. Most importantly one has to have the correct date format for the date string being converted. If it is not the correct string one will receive a zero return or the number of day could be off by 28 or more days off depending on the month and date of the month transposition.



The example also goes over the ISO date and shows what happens when not all of the ISO date is provided.
Not applicable
Sorry, I just got more confused, I'm not great with this. Is there another way I should be doing this? I have a StartDate feild and a EndDate feild. I want the other feild (Total Days) to equal the number of days between the 2 dates. But If 8/8/2008 and 8/8/2008 are choosen for both dates I want the TotalDays to equal 1. Right now I have the below in there and it is calculating right now correctly, but question is will it later useing other dates? Thanks for all yoor help, Lucy