Home > JavaScript > Get first day of previous month on JavaScript

Get first day of previous month on JavaScript

Getting the first day of the previous month is cake in JavaScript:

// get today’s date

var ourDate = new Date();

//roll it back to the last day of last month

ourDate.setDate(-1);

//now that we’re in the proper month, let’s go back to the first day…

ourDate.setDate(0);

// and now we have it

alert(ourDate);

Easy.

Advertisements
Categories: JavaScript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: