I'm fairly new to scripting and have looked for an answer to this; I have found some posts though have been unable to apply them to my scenario.
I have one date that is automatically populated with the current date, and another (earlier) date that the user enters. I need to have a field which calculates the difference between these 2 dates in days.
Any help appreciated - I'll use any help as a learning exercise!
Views
Replies
Total Likes
Here some links around this subject:
Create a date field or entry
Then a calculated readonly date field
In the calculate event of the second field set FormCalc and place the following code:
if (DateField1.rawValue ne null)then
Abs(Date2Num(DateField1.formattedValue, DateFmt(2)) - Date())
else
$.rawValue = ""
endif
And the result is:
Views
Replies
Total Likes
Views
Replies
Total Likes
ok, then a slightly changed form
Datefield2 without pre-population in initialize
# of days calculated with slightly modified script
if (DateField1.rawValue ne null and DateField2.rawValue ne null)then
Abs(Date2Num(DateField1.formattedValue, DateFmt(2)) - Date2Num(DateField2.formattedValue, DateFmt(2)))
else
$.rawValue = ""
endif
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Regarding the change of output format make the following changes:
Set the Data pattern of your 2 date fields to
and the Display pattern to the one you wish to have
Change the calculation script (if you use mine in FormCalc) to
What this does is to use the data format of your fields to get the date values for calculation which stays fixed whereas your display format can then change because we do not use the formattedValue properties any more.
Views
Replies
Total Likes
Views
Likes
Replies