8/24/2012

DateDiff Function

In Access, the DateDiff function returns the difference between two date values, based on the interval specified.
The syntax for the DateDiff function is:
DateDiff ( interval, date1, date2, [firstdayofweek], [firstweekofyear])
interval is the interval of time to use to calculate the difference between date1 and date2. Below is a list of valid interval values.

Interval Explanation
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
date1 and date2 are the two dates to calculate the difference between.
firstdayofweek is optional. It is a constant that specifies the first day of the week. If this parameter is omitted, Access assumes that Sunday is the first day of the week. This parameter can be one of the following values:
Constant Value Explanation
vbUseSystem 0 Use the NLS API setting
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
firstweekofyear is optional. It is a constant that specifies the first week of the year. If this parameter is omitted, Access assumes that the week containing Jan 1st is the first week of the year. This parameter can be one of the following values:
Constant Value Explanation
vbUseSystem 0 Use the NSL API setting
vbFirstJan1 1 Use the first week that includes Jan 1st (default)
vbFirstFourDays 2 Use the first week in the year that has at least 4 days
vbFirstFullWeek 3 Use the first full week of the year

For Example:

DateDiff ("yyyy", #15/10/1998#, #22/11/2003#) would return 5
DateDiff ("m", #15/10/2003#, #22/11/2003#) would return 1
DateDiff ("d", #15/10/2003#, #22/11/2003#) would return 38

VBA Code:

The DateDiff function can be used in VBA code. For example:
Dim LValue As Integer
LValue = DateDiff ("d", #15/10/2003#, #22/11/2003#)
In this example, the variable called LValue would now contain the value of 38.

SQL/Queries:

You can also use the DateDiff function in a query.
copyright www.TechOnTheNet.com

2 comments:

  1. Play Baccarat (FREE) | World-leading Online Casino & Sportsbook
    Play online Baccarat for free or real money งานออนไลน์ right now from World's leading online casino and sportsbook. ✓ No 인카지노 download, no login 바카라 required.

    ReplyDelete
  2. This 1xbet leads to millions of prospects to win with every spin. In addition, Fire Joker is the game that represents the basic slots. If you like a nostalgic experience in a Vegas casino, this ninety four.23& RTP game has it for you. Moreover, NetEnt's Gonzo's Quest will let you experience exploration and adventure in the thrilling tropical jungle.

    ReplyDelete