Date.dateDiff MethodReturns the number of intervals between two dates.object.dateDiff (interval, toDate[, firstDayOfWeek[, calendar]]) string Arguments
SettingsThe interval argument can have the following values:
The firstdayofweek argument can have the following values:
Return ValueThe Date.dateDiff method returns the number of intervals between two dates.RemarksYou 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 |