4.9 DATEDIFF

@DATEDIFF calculates the difference between two dates or datetimes, in days or seconds.

Syntax

@DATEDIFF ("difference", date, date)
"difference"

The difference between the specified dates. Valid values can be:

  • DD to compute the difference in days.

  • SS to compute the difference in seconds.

date

A string in the format of YYYY-MM-DD[*HH:MI[:SS]], where * can be a colon (:) or a blank space.

Examples

Example 1   

To calculate the number of days since the beginning of the year 2000:

differential = (@DATEDIFF("DD","2000-01-01",@DATENOW()))
Example 2   

To calculate the actual day of the year in the above example (@DATEDIFF returns 0 for 2000-01-01):

todays_day = @COMPUTE(@DATEDIFF("DD","2000-01-01",@DATENOW()))+1)