DateDiff function
describe
Returns the time interval between two dates.
grammar
DateDiff(interval,date1,date2[,firstdayofweek][,firstweekofyear]])
The syntax of the DateDiff function has the following parameters:
Parameter description
The interval is required. A string expression that represents the time interval used to calculate date1 and date2. For values, see the Settings section.
date1, date2 is required. Date expression. Two dates used for calculation.
firstdayofweek is optional. Specifies the constant for the first day of the week. If not specified, the default is Sunday. For values, see the Settings section.
firstweekofyear is optional. Specify the constant for the first week of the year. If not specified, the default is the week on January 1st. For values, see the Settings section.
set up
The interval parameter can have the following values:
Setting Description
yyyy
m month
y Years Days
Day
w Number of days of a week
www.
h hours
m minutes
s seconds
The firstdayofweek parameter can have the following values:
Constant value description
vbUseSystem0 uses the Regional Language Support (NLS) API settings.
vbSunday1 Sunday (default)
vbMonday2 Monday
vbTuesday3 Tuesday
vbWednesday4 Wednesday
vbThursday 5 Thursday
vbFriday6 Friday
vbSaturday7 Saturday
The firstweekofyear parameter can have the following values:
Constant value description
vbUseSystem0 uses the Regional Language Support (NLS) API settings.
vbFirstJan11 starts from the week on January 1st (default).
vbFirstFourDays2 starts with the first week of at least four days in the new year.
vbFirstFullWeek3 starts with the first full week of the new year.
illustrate
The DateDiff function is used to determine the number of specified time intervals that exist between two dates. For example, you can use DateDiff to calculate the number of days when the two dates differ, or the number of weeks between the same day and the last day of the year.
To calculate the number of days between date1 and date2, you can use "Days of a Year" ("y") or "Days" ("d"). When interval is "Dates of the Week" ("w"), DateDiff returns the number of weeks between the two dates. If date1 is Monday, DateDiff calculates the number of Mondays before date2. This result contains date2 and not date1. If the 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 Sundays between date1 and date2. If date2 is Sunday, DateDiff will calculate date2, but even if date1 is Sunday, date1 will not be calculated.