VaR dt = new date ();
// Add a day.
VaR newdate = dateadd ("D", 5, DT );
Alert (newdate. tolocaledatestring ())
// Add a month.
Newdate = dateadd ("M", 2, now );
Alert (newdate. tolocaledatestring ())
// Add year
Newdate = dateadd ("Y", 1, now );
Alert (newdate. tolocaledatestring ())
Function dateadd (interval, number, date)
{
/*
* Function: implements the dateadd function of VBScript.
* Parameter: interval, a string expression, indicating the time interval to be added.
* Parameter: Number, numeric expression, indicating the number of time intervals to be added.
* Parameter: date, time object.
* Return: a new time object.
* Var now = new date ();
* Var newdate = dateadd ("D", 5, now );
* --------------- Dateadd (interval, number, date )-----------------
*/
Switch (interval)
{
Case "Y ":
Date. setfullyear (date. getfullyear () + number );
Return date;
Break;
Case "Q ":
Date. setmonth (date. getmonth () + number * 3 );
Return date;
Break;
Case "M ":
Date. setmonth (date. getmonth () + number );
Return date;
Break;
Case "W ":
Date. setdate (date. getdate () + number * 7 );
Return date;
Break;
Case "D ":
Date. setdate (date. getdate () + number );
Return date;
Break;
Case "H ":
Date. sethours (date. gethours () + number );
Return date;
Break;
Case "M ":
Date. setminutes (date. getminutes () + number );
Return date;
Break;
Case "S ":
Date. setseconds (date. getseconds () + number );
Return date;
Break;
Default:
Date. setdate (D. getdate () + number );
Return date;
Break;
}
}