DateDiff()

Top  Previous  Next

DateDiff() - Calculate the Difference Between Two Dates

Description

The DateDiff() function is used to compare two dates and calculate the period between them in days, months, years, hours, minutes or seconds.

DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])

Parameters
The interval is a string expression representing the type of interval to increase or decrease the date by. See the table below for possible values:

Value

Description

d

Day

m

Month

yyyy

Year

w

Weekday

y

Day of year

ww

Week of year

q

Quarter

h

Hour

n

Minute

s

Second

The date1 and date2 parameters are used to specify the initial and final dates for comparison.

The optional parameter firstdayofweek specifies the [id=44#days]day of the week[/id] to use as the first day. If not specified, Sunday is the default value.

The optional firstweekofyear parameter specific the how the [id=44#weeks]first week of the year[/id] is defined.

Examples
If you where born on April 1st, 1964 you could calculate you age in days using the following function:

DaysOld = DateDiff("d", "1-Apr-64", Now)

You could calculate the number of seconds since New Years Day using this example: 

SecondsNYD = DateDiff("s", "1-Jan-" & Year(Now), Now)