Method: DateDiff for VBS
- Updated2024-09-12
- 2 minute(s) read
Methods > Method: DateDiff for VBS
Method: DateDiff for VBS
Specifies the number of timespans between two dates.
vDateDiff = Object.DateDiff(interval, date1, date2, [firstdayofweek], [firstdayofyear])
Object | VBS Object with this method. You do not need to specify this object. | ||||||||||||||||||||
interval | Variant Specifies the timespan. The following settings are possible.
| ||||||||||||||||||||
date1 | Variant Specifies the first date. If you do not enter the year, the DateDiff method uses the current year. | ||||||||||||||||||||
date2 | Variant Specifies the second date. If you do not enter the year, the DateDiff method uses the current year. | ||||||||||||||||||||
[firstdayofweek] | Variant Specifies the weekday. Possible values are vbSunday, vbMonday, vbTuesday, vbWednesday, vbThursday, vbFriday, vbSaturday and vbUseSystem. If you do not enter a value, the DateDiff method uses Sunday. This setting only considers the method for the "w" and "ww" timespans. | ||||||||||||||||||||
[firstdayofyear] | Variant Specifies the first week of the year. Possible values are vbFirstJan1, vbFirstFourDays, vbFirstFullWeek, and vbUseSystem. If you do not enter a value, the DateDiff method uses January 1. | ||||||||||||||||||||
vDateDiff | Variant Receives the number of timespans. |
The following example returns various timespans:
MyDate = DateDiff("yyyy", #31/12/2001#, #01/01/2002#) Call MsgBox("Years left: " & MyDate) MyDate = DateDiff("ww", "01/01", Date) Call MsgBox("Week of year: " & MyDate) MyDate = DateDiff("ww", #01 January#, Date) Call MsgBox("Week of year: " & MyDate)
See Also
Related Topics
DateAdd | DateDiff | DatePart | DateSerial | DateValue | Date | Day | Hour | Minute | MonthName | Month | Now | Second | TimeSerial | TimeValue | Time | Timer | Weekday | WeekdayName | Year