Skip to content

Instantly share code, notes, and snippets.

@balanceiskey
Created February 8, 2012 21:25
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 balanceiskey/1774007 to your computer and use it in GitHub Desktop.
Save balanceiskey/1774007 to your computer and use it in GitHub Desktop.
Date Math in Javascript
// calculate end day
// note, end day should be the final second
// of the final day (23:59:59) and 1 day
// before today
var end_time = parseInt(new Date().setUTCHours(23,59,59,59)/1000 - 86400, 10),
// calculate start day, x number of days before
// end day, note start day should be the start
// of the day (00:00:00)
start_time = parseInt(new Date((end_time - (days_ago * 86400)) * 1000).setUTCHours(0,0,0,0) / 1000, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment