Return the time interval between two dates.
Syntax
DateDiff (interval,date1,date2[, FirstDayofWeek [, FirstWeekofYear]])
Key
date1 The first date to compare
date2 The second date to compare
FirstDayofWeek A constant defining the first day of the week:
vbUseSystem (0), vbSunday (1=default),vbMonday(2),
vbTuesday(3), vbWednesday(4), vbThursday(5),
vbFriday(6), vbSaturday(7)
FirstWeekofYear A constant defining the first week of the year:
vbUseSystem(0), vbFirstJan1(1),vbFirstFourDays(2),
vbFirstFullWeek(3)
interval The date/Time interval to express the result:
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
h Hour
n Minute
s Second
Example
dtm1="18-Feb-10"
dtm2="19-Aug-10"
WScript.Echo "Difference between " & dtm1 & " and " & dtm2
intMonthsDifferent=DateDiff("m", dtm1, dtm2)
WScript.Echo intMonthsDifferent
“Listen to many, speak to a few” ~ William Shakespeare
Related:
Date - The current system date
DateAdd - Add a time interval to a Date
DatePart - Return a unit of time from a date
DateSerial - Return a Date from a numeric Year, Month and Day
Weekday - Return the day of the week
Equivalent PowerShell cmdlet: New-TimeSpan