HarleyPig's Scripture Study Journal


Date Parsing In Javascript

16 Jul 2008

I needed to reliably parse date input in javascript today. The default javascript parse routine sucks mud.

Google had some interesting results (at least one of which I'll be posting about later).

I found Datejs. It works almost as well as perl's DateTime. In some ways, better. And it's fast too. I'm still getting used to JavaScript's funky syntax but I ended with the following structure:

if ( (5).days().fromNow() > Date.parse( document.getElementById( 'newhours' ).value )

So easy and simple. Of course, I should probably get rid of that magic number, but this works for now.