Expand my Community achievements bar.

Using Formcalc to calculate Days between Dates

Avatar

Former Community Member

I received the following reply to my previous question, but need help applying it.

Use the following FormCalc script:

var numDays;

numDays = Date2Num("21/5/2012", "DD/M/YYYY") - Date2Num("19/5/2012", "DD/M/YYYY");

How do I apply in this situation?  I have a date field named "RehireDate" and a date field "SepDate."  I have a numeric field in which I want to subtract the RehireDate from the SepDate to get a specific number of days.  Do I substitute the dates in quotes above with my field names?  Also, how do I get the "DD/M/YYYY" date format?  I cannot find it in the Validation pattern. 

1 Reply

Avatar

Employee

Write the foll. formcalc script to get the number of days in a numeric field. You can write this script on exit event of the second date time field.

// form1.sf1.DateField2::exit - (FormCalc, client)

   

form1.sf1.NumericField2.rawValue = Date2Num(DateField1, "YYYY-MM-DD") - Date2Num(DateField2, "YYYY-MM-DD");

Hope this helps.