Home > Language Reference > Date/Time Functions > DateBetween

DateBetween

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

Syntax

var=DateBetween(<interval>, <date1>, <date2>)

Parameters

<interval>, string, kind of interval to use. The possible values are:
 <interval> parameter  Description
 d  Day
 w      Weekday
 ww  Week
 y  Day of year
 yyyy  Year
 q      Quarter
 m  Month
 h  Hour
 n  Minute
 s  Second

<date1>, string, start date. The format is the short date format as specified in Language and Region Settings (for example 12/23/2013).

<date2>, string, end date.

Return value

var, integer, number of intervals between the two dates. If <date2> is before <date1>, a negative integer is returned. If the function fails, the return value is 0 and standard Error Handling is used.

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 of <date1> (see second example).

See also

Date$
DateToDate$
Day$
Hour$
Hundreds
Min$
Month$
Sec$
Time$
WeekDay
Year$

Examples

var=DateBetween( "d","12/01/2013","12/31/2013") 'returns 30

var=DateBetween( "w","12/24/2007","12/30/2007") 'returns 0 as 24 December 2007 is a Monday

var=DateBetween("s","10/12/2013 07:05:00","10/12/2013 07:05:10")  'returns 10