DateDiff Function

See AlsovbfctDateDiffSee                 ExamplevbfctDateDiffEx>Low

Description

Returns a Variant8PHEAW3 containing the number of time intervals between two specified dates.

Syntax

DateDiff( interval, date1, date2 )

Remarks

The DateDiff function uses the following parts:

Part                 Description

 

interval             String expression1330R89 that is the interval of time you use to calculate the difference between date1 and date2.

date1, date2      Two dates you want to use in the calculation.

 

You can use the DateDiff function to determine how many specified time intervals exist between two dates.  For example, you might use DateDiff to calculate the number of days between two dates or the number of weeks between today and the end of the year.

The following table lists the valid time periods and their interval values.  These intervals are also used by the Format function.

Time period     Interval

 

Year                 yyyy

Quarter             q

Month               m

Day of Year      y

Day                  d

Weekday          w

Week               ww

Hour                 h

Minute              n

Second             s

 

If you want to know the number of days between date1 and date2, you can use either Day of Year or Day ("y" or "d").

When interval is Weekday ("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 date1 but not date2.  If interval is Week ("ww"), however, the DateDiff function returns the number of calendar weeks between the two dates.  It counts the number of Sundays between date1 and date2.  DateDiff counts date1 if it falls on a Sunday; but it doesn't count date2, even if it does fall on a Sunday.

If date1 refers to a later point in time than date2, the DateDiff function returns a negative number.

 

Distribution Note   When you create and distribute applications that use this function in your code, you should install the file MSAFINX.DLL in the customer's Microsoft Windows \SYSTEM directory.  The Visual Basic Setup KitGUH5X7 provides tools to help you write setup programs that install your applications.