Demo Extending The JavaScript Date Object with User Defined Methods

Read the original Digital Web article Extending The JavaScript Date Object with User Defined Methods by Lawrence O'Sullivan.

The methods are grouped by how they act on the date and whether they need addtional information. You can change the start date, number to add, and enddate. Rather than using several buttons there is just one per section. Similarly, there's just one field for the number of days, weekdays, weeks, months, and years to add to the start date. The number entered is used as the appropriate units for the method.

Starting Date
Methods Returning Date Information
MethodReturn Value
getFullDay 
getDayAbbr 
getFullMonth 
getMonthAbbr 
to12HourTimeString 
to24HourTimeString 
lastday 
getDayOfYear 

Methods Adding to Dates

Enter a number for days, weeks, etc. to add to the start date.

MethodNew Date
addDays 
addWeekDays 
addWeeks 
addMonths 
addYears 
End Date

The following methods require two dates. The start date above is used with the end date. The call is startDate.method(endDate);

Difference Between Two Dates
MethodReturn Value
getDaysBetween  
getWeekDays  
getMonthsBetween* 
getYearsBetween* 
Dates of Same Day Each Week Between Dates
MethodWeek DayResults
sameDayEachWeek
 

I hope you find this useful.

* The results were rounded to two decimals using toFixed.