Skip to content

Instantly share code, notes, and snippets.

@ecowden
Created January 18, 2013 21:19
Show Gist options
  • Save ecowden/4568631 to your computer and use it in GitHub Desktop.
Save ecowden/4568631 to your computer and use it in GitHub Desktop.
User the SugarJS date functions to find Mondays
/*
* SugarJS is a super handy tool for common JavaScript functions.
*
* Recently, we needed to find Mondays. This Monday, next Monday, three Mondays ago...Mondays
* for everyone! SugarJS made this kind of logic dead simple. Here is one way to
* tackle the problem.
*/
var thisMonday = Date.create().beginningOfWeek().addDays(1);
var eightMondaysAgo = Date.create().rewind({days: 7 * 8}).beginningOfWeek().addDays(1);
var threeMondaysFromNow = Date.create().advance({days: 7 * 3}).beginningOfWeek().addDays(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment