Sunday, October 3, 2010

Visual Basic Date and Time Function : DateDiff

Purpose : The DateDiff function returns a Long data type the number of time intervals between two specified dates

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

Interval : 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.
Firstdayofweek : A constant that specifies the first day of the week. If not specified, Sunday is assumed.
Firstweekofyear : A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.

Dim TheDate As Date ' Declare variables.
Dim Msg
TheDate = InputBox ("Enter a date")
Msg = "Days from today: " & DateDiff("d", Now, TheDate)
MsgBox Msg

No comments:

Post a Comment