Copy Code code as follows:
DATE.PROTOTYPE.DATEADD = function (Interval,number)
{
var d = this;
var k={' y ': ' fullyear ', ' Q ': ' Month ', ' m ': ' Month ', ' W ': ' Date ', ' d ': ' Date ', ' H ': ' Hours ', ' n ': ' Minutes ', ' s ': ' Seconds ', ' Ms ': ' milliseconds '};
var n={' Q ': 3, ' W ': 7};
Eval (' D.set ' +k[interval]+ ' (D.get ' +k[interval]+ ' () + ' + ' + (n[interval]| | 1) (*number) + ') ');
return D;
}
Date.prototype.dateDiff = function (Interval,objdate2)
{
var d=this, i={}, T=d.gettime (), T2=objdate2.gettime ();
i[' y ']=objdate2.getfullyear ()-d.getfullyear ();
i[' q ']=i[' y ']*4+math.floor (Objdate2.getmonth ()/4)-math.floor (D.getmonth ()/4);
i[' m ']=i[' y ']*12+objdate2.getmonth ()-d.getmonth ();
i[' Ms ']=objdate2.gettime ()-d.gettime ();
i[' W ']=math.floor ((t2+345600000)/(604800000))-math.floor ((t+345600000)/(604800000));
i[' d ']=math.floor (t2/86400000)-math.floor (t/86400000);
i[' h ']=math.floor (t2/3600000)-math.floor (t/3600000);
i[' n ']=math.floor (t2/60000)-math.floor (t/60000);
i[' s ']=math.floor (t2/1000)-math.floor (t/1000);
return I[interval];
}
DateAdd Method
Returns the Date object for which the specified time interval has been added.
Dateobj.dateadd (interval, number)
Parameters
Dateobj
Required option. Any Date object.
Interval
Required option. A string expression that represents the time interval to add. For numeric values, see the "Settings" section.
Number
Required option. Numeric expression that represents the number of time intervals to add. Numeric expressions can be positive (get future dates) or negative numbers (get past dates).
DateDiff Method
Returns the time interval between two date objects.
Dateobj.datediff (interval, dateObj2)
Parameters
Interval
Required option. A string expression that is used to calculate the time interval between Date1 and Date2. For numeric values, see the "Settings" section.
Dateobj, DateObj2
Required option. The Date object. The two date objects used for the calculation.
Set up
The interval parameter can have the following values:
set |
description |
y |
year |
q |
quarterly |
m |
month |
d |
day |
w |
Week |
h |
hours |
n |
minutes |
s |
seconds |
ms |
milliseconds |