NexJ Logo

DateDiffHours()

Gives the difference in the number of hours 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

DateDiffHours(<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. The first field contains a date value that represents January 31, 2000 9:00 AM EST, and the second field contains a date value that represents January 31, 2000 5:00 PM EST.

  • The expression DateDiffHours($date_started, $date_finished) returns -8.0.
  • The expression DateDiffHours($date_finished, $date_started) returns 8.0.
  • The expression DateDiffHours($date_started, $date_finished, "PST") returns -8.0.

Time zones