nodejs date string formats

Here’s how to work with the date object in nodejs.

The best way to work with dates is to install the dateformat package. It’s quick and easy with npm:

That’s it!

Now you’ll want to include it in your projects like so:

Next, we’ll create a date object called now containing the current date to work with:

So let’s try printing out what we have now:

Naturally, we’re not actually formatting the date yet, so it just shows in the default format like this:

I’m often working with mySQL databases, and need to compare dates, so I use this method: