DateDiffThe function is used to determine the number of specified time intervals that exist between two dates. For example, you can use DateDiffCalculates the number of days between two dates, or the day of the week between the last day of the current year.
To calculate the number of days between date1 and date2 , you can use the days of the year ("Y") or the "Day" ("D"). When interval is "Days of the Week" ("W"),DateDiff Returns the number of weeks between two dates. If date1 is Monday, DateDiff calculates the number of Monday before Date2 . This result contains Date2 and does not contain date1. If interval is "Week" ("WW"), the DateDiff function returns the number of weeks between two dates in the Calendar table. The function calculates the number of Sunday between date1 and date2 . If date2 is Sunday,DateDiff calculates date2, but even if date1 is Sunday, date1is not counted.
If date1 is later than Date2, the DateDiff function returns a negative number.
The firstdayofweek parameter has an effect on the calculations that use the "w" and "ww" interval symbols.
If date1 or date2 is a date literal, the specified year becomes a fixed part of the date. However, if date1 or date2 is included in quotation marks ("") and the year is omitted, the current year is inserted each time the date1 or date2 expression is evaluated in the code. This allows you to write program code that applies to different years.
When the interval is "year" ("yyyy"), compare December 31 and the next year January 1, although actually only one day,DateDiff returns 1 indicates a difference of one year.