Skip to main content Accessibility Feedback

JavaScript and dates revisited

Two quick things…

1. A correction

In last week’s post on checking if a date is valid with JavaScript, I incorrectly said you needed to pass in the month as a 0 - 11 integer (example, March is 2).

This is incorrect. The function automatically adjusts the date for you. I updated the original post accordingly.

2. A helper library

If you need to do extensive work with dates, reader Erik Grubaugh recommended Moment.js.

It’s a library that makes it easier to get, set, manipulate, and display dates with JavaScript. It looks awesome, but at 126kb, it’s rather large (almost as big as jQuery), so I’d only recommend using it if you’re doing a lot of date work.