Skip to content

Instantly share code, notes, and snippets.

@jonkemp
Created December 18, 2012 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonkemp/4332432 to your computer and use it in GitHub Desktop.
Save jonkemp/4332432 to your computer and use it in GitHub Desktop.
Get the current date and the date 30 days ago. Then format the dates like this: M/D/YYYY. This an example of date manipulation in JavaScript.
/**
* Get the current date and the date 30 days ago.
* Then format the dates like this: M/D/YYYY.
*/
var diff = 2592000000;
var now = new Date();
var diffDate = new Date( now.getTime() - diff );
var nowPrint = [ now.getMonth() + 1, now.getDate(), now.getFullYear() ].join("/");
var diffPrint = [ diffDate.getMonth() + 1, diffDate.getDate(), diffDate.getFullYear() ].join("/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment