DATEDIFF returns the number of time intervals between two specified dates.
SYNTAX:
DATEDIFF(Interval,Date1,Date2)
Interval: The interval of time you use to calculate the difference between date1 and date2. The following table displays the valid Intervals.
"yyyy" |
Year |
"y" |
Day of Year |
"q" |
Quarter |
"m" |
Month |
"d" |
Day |
"w" |
Weekday |
"ww" |
Week |
"h" |
Hour |
"n" |
Minute |
"s" |
Second |
date1: A string representing a valid date, i.e. "1/2/2004", a cell reference to a cell containing a string, or a function that returns a date string (such as DSORT)
date2: A string representing a valid date, i.e. "1/2/2004", a cell reference to a cell containing a string, or a function that returns a date string (such as DSORT)
NOTES:
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.
To calculate the number of days between date1 and date2, you can use either Day of year ("y") or Day ("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 date2 but not date1. 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 date2 if it falls on a Sunday; but it doesn't count date1, 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.
EXAMPLES:
DateDiff("M","1/31/2004","2/2/2004") - Returns 1.
DateDiff("D",A1,A2) - Returns 30. Cell A1 = 1/1/2004, A2 = 1/31/2004
DATEDIFF("D",DATE(1,"mm/dd/yy",1),DATE(-1,”mm/dd/yy”,-1))+1 - Returns the number of days in the report.