O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

DateDiff Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

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

A String expression (see the first item in Section ) or a member of the DateInterval enumeration (see the second item in Section ) that specifies the units of time 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.

Rules at a Glance

  • interval can 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

  • interval can also be a member of the DateInterval enum:

    Enum DateInterval
       Day
       DayOfYear
       Hour
       Minute
       Month
       Quarter
       Second
       Week
       Weekday
       WeekOfYear
    End Enum
  • To calculate the number of days between date1 and date2, you can use either of the DateInterval constants, DayOfYear or Day, or the string literals "y" or "d".

  • When interval is Weekday or "w", DateDiff

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required