Name

DateDiff Function — Microsoft.VisualBasic.DateAndTime

Synopsis

DateDiff(interval, date1, date2[, dayofweek[, weekofyear]])
interval required; String or DateInterval enum

Specifies the time unit used to express the difference between date1 and date2

date1, date2 required; Date or a literal date

The starting and ending dates, whose difference is computed as date2- date1

dayofweek optional; FirstDayOfWeek enum

A member of the FirstDayOfWeek enum

weekofyear optional; FirstWeekOfYear enum

A member of the FirstWeekOfYear enum

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.

interval can be one of the following literal strings:

yyyy

Year

q

Quarter

m

Month

y

Day of year

d

Day

w

Weekday

ww

Week

h

Hour

n

Minute

s

Second

interval can also be a member of the DateInterval enum:

Enum DateInterval
   Day
   DayOfYear
   Hour
   Minute
   Month
   Quarter
   Second
   Week
   Weekday
   WeekOfYear
End Enum

When interval is Weekday or "w", DateDiff returns the number of weeks between the two dates. If date1 falls on a Monday, DateDiff counts the number of Mondays until date2. It counts date2, but not date1. If interval is Week or "ww", however, DateDiff returns the number of calendar weeks between the two dates. It counts the number of Sundays between date1 and date2. DateDiff counts date2 if it ...

Get VB.NET Language Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.