|
Date.dateAdd Method
Returns the number of intervals between two dates.
object.dateAdd (interval, n[, calendar])
string
Arguments
- object
- Required. Always the name of a Date object. This is
used 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.
- n
- Required. The number of interval you want to add. The numeric
expression can either be positive, for dates in the future, or
negative, for dates in the past.
- 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 |
wd or workday |
Working day |
d or day |
Day |
h or hour |
Hour |
n or minute |
Minute |
s or second |
Second |
Return Value
The Date.dateAdd method returns a date to which a specified time interval has been added.
var oCCal = new CustomCalendar();
oCCal.Add(new Date("11/26/2009"));
oCCal.Add(new Date("11/27/2009"));
oCCal.Add(new Date("12/25/2009"));
oCCal.Add(new Date("1/1/2010"));
Console.Writeln((new Date("11/20/2009")).dateAdd("d", 30).format("mm/dd/yyyy")); // returns 12/20/2009
Console.Writeln((new Date("11/20/2009")).dateAdd("wd", 30).format("mm/dd/yyyy")); // returns 01/01/2010 because no calendar was given to define holidays
Console.Writeln((new Date("11/20/2009")).dateAdd("wd", 30, oCCal)); // returns 01/07/2010
Requirements
|