IR Framework

Date.dateDiff Method

Returns the number of intervals between two dates.
object.dateDiff (interval, toDate[, firstDayOfWeek[, calendar]])

string

Arguments

object
Required. Always the name of a Date object. This is u sed as the beginning date for the calculation.


interval
Required. String expression that is the interval you want to use to calculate the differences between date1 and date2. See Settings section for values.


toDate
Required. The Date object that defines the end date for the calculation.


firstDayOfWeek
Optional. Constant that specifies the day of the week. If not specified, Sunday is assumed. See Settings section for values.


calendar
Optional. A CustomCalendar object used to define the holidays (non-working weekdays) between the two dates. This is used when calculating the number of workdays between the two dates. If omitted, a generic calendar containing no holidays is used.



Settings

The interval argument can have the following values:
Setting Description
y or year Year
q or quarter Quarter
m or month Month
w or week Week
ww or calweek Calendar week
wd or workday Working day
d or day Day
h or hour Hour
n or minute Minute
s or second Second


The firstdayofweek argument can have the following values:
Value Description
0 Sunday (default)
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday

Return Value

The Date.dateDiff method returns the number of intervals between two dates.

Remarks

You can use the Date.dateDiff method to determine how many specified time intervals exist between two dates. For example, you might use Date.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 (object) and date2 (toDate), use Day ("d"). When interval is Weekday ("w"), Date.dateDiff returns the number of weeks between the two dates. Use firstdayofweek to choose where to set the week boundary.

If date1 refers to a later point in time than date2, the Date.dateDiff method returns a negative number.

When comparing December 31 to January 1 of the immediately succeeding year, Date.dateDiff for Year ("y") returns 1 even though only a day has elapsed.

The following example uses the Date.dateDiff method to display the number of days between a given date and today:



Console.Writeln((new Date("11/20/2009")).dateDiff("w", new Date("11/28/2009"), 6));		//	returns 2
Console.Writeln((new Date("11/20/2009")).dateDiff("w", new Date("11/28/2009"), 5));		//	returns 1
var oCCal = new CustomCalendar();
oCCal.Add(new Date("11/26/2009"));
oCCal.Add(new Date("11/27/2009"));
Console.Writeln((new Date("11/20/2009")).dateDiff("d", new Date("11/28/2009"), 5));		//	returns 8
Console.Writeln((new Date("11/20/2009")).dateDiff("wd", new Date("11/28/2009"), 5, oCCal));		//	returns 3


Requirements