JavaScript Date Ranges/Calculations with Datejs



If there is anything I hate more than the smell of durian, it is having to deal with date range calculations in JavaScript. Luckily though, we have the Datejs JavaScript Date Library to prevent us from having to pull our hair out.

Mission

I was recently faced with having to implement a date range drop-down menu very similar to of the one that is beautifully implemented in Google Adwords:

Google Adwords Date Range Pull-Down Menu

The select input element had to return 3 pieces of information: The name of the option, start date, and end date of the selected option.

Here are the specific options that I had to implement for the date ranges:

  • This month to date
  • This quarter to date
  • Last 7 days
  • Last 30 days
  • Last 365 days
  • Last week (Mon to Sun)
  • Last full month
  • Last full quarter
  • Last full year

The Plan

Continue reading JavaScript Date Ranges/Calculations with Datejs