DateBetween – Date/Time Functions**





DateBetween Function


Description

The DateBetween function returns the number of specified time intervals between two dates.

Usage

It can return the number of days between two dates, the number of weeks between today and the end of the year, etc.

Syntax

val = DateBetween(<interval$>, <date1$>, <date2$>)

Parameters

  • <interval$>: string specifying the time interval you want to use as the unit of difference between <date1$> and <date2$>.
  • <date1$>: string, first date value to use in the calculation. The date format must be the one as in Regional settings (05/01/2007 for 1st of May in US format, 01/05/2007 in European format).
  • <date2$>: string, second date value to use in the calculation.

<interval$> Values

Value Unit of Time Difference
d Day
w Weekday
ww Week (number of weeks), same as w
y Day of the year, same as d
yyyy Year (number of years)
q Quarter (number of quarters)
m Month (number of months)
h Hours (number of hours)
n Minutes (number of minutes)
s Seconds (number of seconds)

Return Value

Returns the number of time intervals as an integer. If one of the parameters is incorrect (invalid date for example) and if #IgnoreErrors=1, the function returns 0. A negative number is returned if <date2$> is before <date1$>.

Remarks

  • If the year is not included in <date$>, the current year is added automatically.
  • If <interval$> is “w” and <date1$> is a Monday, the function returns the number of Mondays between <date1$> and <date2$> without taking the first Monday <date1$> (see second example).