Name
DateDiff Function
Class
Microsoft.VisualBasic.DateAndTime
Syntax
DateDiff(interval, date1, date2[,dayofweek[,weekofyear]])
-
interval(required; String orDateIntervalenum) A String expression (see the first item in Section ) or a member of the
DateIntervalenumeration (see the second item in Section ) that specifies the units of time used to express the difference betweendate1anddate2-
date1,date2(required; Date or a literal date) The starting and ending dates, whose difference is computed as
date2-date1-
dayofweek(optional;FirstDayOfWeekenum) A member of the
FirstDayOfWeekenum-
weekofyear(optional;FirstWeekOfYearenum) A member of the
FirstWeekOfYearenum
Return Value
A Long specifying the number of time intervals between the two dates
Description
Calculates the number of time intervals between two dates. For example, you can use the function to determine how many days there are between 1 January 1980 and 31 May 1998.
Rules at a Glance
intervalcan be one of the following literal strings:
|
String |
Description |
|---|---|
yyyy |
Year |
q |
Quarter |
m |
Month |
y |
Day of year |
d |
Day |
w |
Weekday |
ww |
Week |
h |
Hour |
n |
Minute |
s |
Second |
intervalcan also be a member of theDateIntervalenum:Enum DateInterval Day DayOfYear Hour Minute Month Quarter Second Week Weekday WeekOfYear End Enum
To calculate the number of days between
date1anddate2, you can use either of theDateIntervalconstants,DayOfYearorDay, or the string literals"y"or"d".When
intervalisWeekdayor"w", DateDiff
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access