Name
DateDiff Function
Class
Microsoft.VisualBasic.DateAndTime
Syntax
DateDiff(interval, date1, date2[, dayofweek[, weekofyear]])-
interval Use: Required
Data Type: String or
DateIntervalenumA 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 Use: Required
Data Type: Date or a literal date
The starting and ending dates, whose difference is computed as
date2-date1-
dayofweek Use: Optional
Data Type:
FirstDayOfWeekenumA member of the
FirstDayOfWeekenum-
weekofyear Use: Optional
Data Type:
FirstWeekOfYearenumA 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 |
|---|---|
|
|
Year |
|
|
Quarter |
|
|
Month |
|
|
Day of year |
|
|
Day |
|
|
Weekday |
|
|
Week |
|
|
Hour |
|
|
Minute |
|
|
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 ...
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