@DATEDIFF function to calculate the difference between two dates or datetimes, in days or seconds.
@DATEDIFF ('difference', 'date', 'date')
The difference between the specified dates. Valid values can be:
DD, which computes the difference in days.
SS, which computes the difference in seconds.
A string within single quote marks, in the format of
'YYYY-MM-DD[*HH:MI[:SS]]', where * can be a colon (:) or a blank space, or the
@DATENOW function without quotes to return the current date.
The following calculates the number of days since the beginning of the year 2011.
YTD = @DATEDIFF ('DD', '2011-01-01', @DATENOW ())
The following calculates the numerical day of the year. (
@DATEDIFF returns 0 for
todays_day = @COMPUTE (@DATEDIFF ('DD', '2011-01-01', @DATENOW ()) +1)