DATEDIFF(interval, date1, date2 [,firstdayofweek] [,firstweekofyear]) |
Returns the number of a given time interval between two specified dates (Long). |
interval | The interval of time you want to calculate (String): "yyyy","YYYY" = year "q","Q" = quarter "m","M" = month "y","Y" = day of year "d","D" = day "w","W" = weekday "ww","WW" = week "h","H" = hour "n","N" = minute "s","S" = second |
date1 | The start date (Date). |
date2 | The finish date (Date). |
firstdayofweek | (Optional) A vbDayOfWeek constant that specifies the first day of the week: 0 = vbUseSystemDayofWeek 1 = vbSunday (default) 2 = vbMonday 3 = vbTuesday 4 = vbWednesday 5 = vbThursday 6 = vbFriday 7 = vbSaturday |
firstweekofyear | (Optional) A vbFirstWeekOfYear constant that specifies the first week of the year: 0 = vbUseSystem 1 = vbFirstJan1 (default) 2 = vbFirstFourDays 3 = vbFirstFullWeek |
REMARKS |
* If "date1" or "date2" are enclosed in double quotation marks and the year is not entered then the current year is used. * If "date1" > "date2" then a negative number is returned. * If "firstdayofweek" is left blank, then 1 is used (ie Sunday). * If "firstweekofyear" is left blank, then the first week is assumed to be the week in which January 1 occurs. * The "firstdayofweek" is only relevant if the "interval" is either "w" or "ww". * This function can be used to determine how many specified time intervals exist between two dates. * You can use the DATEADD function to return the date with a specified time interval added. * You can use the DATEPART function to return the specified part of a given date. * The equivalent .NET function is Microsoft.VisualBasic.DateAndTime.DateDiff * For the Microsoft documentation refer to docs.microsoft.com |
Debug.Print DateDiff("d",Date(), "31/12/2021",3,0) '= 117
Debug.Print DateDiff("d",Date(), "31/12/2004",2,0) '= -6092
Debug.Print DateDiff("yyyy","31 Dec 2003","1 Jan 2004") '= 1
Debug.Print DateDiff("d", #12/1/2001#, #12/1/2000#, 0, 0) '= -365 - 2000 is a leap year so Feb has 28 days
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited Top