NexJ Logo

DateDiffDays()

Gives the difference in the number of days between two specified dates. This function takes two date values and a string value as arguments and returns a number value. The difference is calculated by subtracting the second date from the first date. The number is positive if the first argument has a later date and time than the second argument, negative if the first argument has an earlier date and time than the second argument, and zero if the two arguments are the same.

Syntax

DateDiffDays(first_date, second_date, time_zone)

Input

first_date

date

The first date to compare.

second_date

date

The second date to compare.

time_zone

string

(Optional) The time zone code. This argument specifies the time zone of the dates. For example, if you want the dates to be in Eastern Standard Time (EST), enter the time zone argument "EST". If you do not specify a time zone, the local time zone of the user who is completing the form is used.

Output

number

Examples

Assume that you have a form in which there is a date field question with the reference name date_started, and a date field question with the reference name date_finished. In the first date field, the user chooses January 1, 2000. In the second date field, the user chooses January 10, 2000. The user is in the EST time zone.

  • The expression DateDiffDays($date_started, $date_finished) returns -9.0.
  • The expression DateDiffDays($date_finished, $date_started) returns 9.0.
  • The expression DateDiffDays($date_started, $date_finished, "PST") returns -9.0.

Time zones