DateDiff() returns how many specified interval boundaries occur between two Date values. Choose the interval carefully: a year result counts year boundaries, while a day result counts day boundaries.
DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
The last two arguments are optional and matter mainly for calculations involving weeks.
Dim d_diff
d_diff = DateDiff("m", #2/28/2003#, #2/28/2006#)
Response.Write "Difference in months: " & d_diff
DateDiff("yyyy",...) can return 1 when two dates are only a day apart but fall in different calendar years. Use the interval that matches the question you are answering.| Interval | Meaning |
|---|---|
| yyyy | Year |
| q | Quarter |
| m | Month |
| y / d | Day |
| w | Weekday boundary |
| ww | Calendar week |
| h | Hour |
| n | Minute |
| s | Second |
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.