Skip to content

Instantly share code, notes, and snippets.

@martindale
Created July 24, 2013 22:57
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 martindale/6075389 to your computer and use it in GitHub Desktop.
Save martindale/6075389 to your computer and use it in GitHub Desktop.
This should generate a series of 1-day timeslices for the previous 30 days (including current day).
var start = new Date();
start.setHours('0');
start.setMinutes('0');
start.setSeconds('0');
start.setMilliseconds('0');
var end = new Date( start.getTime() );
end.setDate( end.getDate() + 1 );
var queries = [];
for (var d = 30; d > 0; d--) {
start.setDate( start.getDate() - d );
end.setDate( start.getDate() + 1 );
queries.push({
$gte: start
, $lt: end
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment