describe
Returns the time interval between two dates.
grammar
Datediff (interval, date1, date2 [, firstDayOfweek [, firstweekoFyear]])
The grammar of the Datediff function has the following parameters:
Parameter description
Interval must be selected. String Expression indicates the time interval between Date1 and Date2. For values, see the setting part.
Date1, date2 must be selected. Date expression. Two dates for calculation.
FIRSTDAYOFWEK optional. The constant on the first day in the specified week. If it is not specified, the default is Sunday. For values, see the setting part.
FirstWeekoFyear optional. Specify the constant of the first week of the year. If it is not specified, it is default to the week of January 1. For values, see the setting part.
set up
The interval parameter can have the following values:
Set description
yyyy year
Q quarter
N month
Y one year
D day
W for a week
ww week
H hour
M minutes
S seconds
The firstDayOfweek parameter can have the following value:
Specific value description
VBUSESYSTEM 0 uses regional language support (NLS) API settings.
VBSunday 1 Sunday (default)
vbmonday 2 Monday
VBTUESDAY 3 Tuesday
VBWednesday 4 Wednesday
VBTHURSDAY 5 Thursday
VBFRIDAY 6 Friday
VBSATURDAY 7 Saturday
The firstweekofyear parameter can have the following value:
Specific value description
VBUSESYSTEM 0 uses regional language support (NLS) API settings.
VBFIRSTJAN1 1 starts from the week of January 1 (default).
VBFIRSTFOURDAYS 2 starts from the first week of at least four days in the new year.
VBFIRSTFULLLWEK 3 starts with the first complete week in the new year.
illustrate
The DateDiff function is used to determine the number of specified time interval between two dates. For example, DateDiff can be used to calculate the number of days difference between two dates, or the weekly number between the day and the last day of the year.
To calculate the number of days between Date1 and Date2, you can use the number of days (Y) or day (d) of one year. When Interval is the number of days (W) of the week (W), DateDiff returns the weekly number between two dates. If Date1 is Monday, the number of Datediff is calculated to Date2 before the number of Monday. This result contains Date2 without Date1. If the interval is week (ww), the Datediff function returns the weekly number between two dates in the calendar table. The number of functions between Date1 and Date2 is calculated. If Date2 is Sunday, Datediff will calculate Date2, but even if Date1 is Sunday, Date1 will not be calculated.
If Date1 is later than Date2, the DateDiff function returns negative numbers.
The firstDayOfweek parameter affects the calculation of the WW interval symbol.
If Date1 or Date2 is a date text, the specified year will become a fixed part of the date. However, if Date1 or Date2 is included in the quotation marks () and omitted the year, each time the Date1 or Date2 expression is calculated in the code, it will be inserted into the current year. In this way, you can write a program code suitable for different years.
When the interval is the year (yyyy), compared with January 1st on December 31st and the coming year, although there is actually only one day, Datediff returns 1 to indicate a year difference.
The example below uses the DateDiff function to show the number of days between today and the given date:
FUNCTION DIFFADATATE (Thedate)
Diffadate = Number of days starting from the same day: & datingiff (d, now, thedate)
End function