Skip to content

Instantly share code, notes, and snippets.

@benkn
Created July 13, 2014 22:55
Show Gist options
  • Save benkn/cb00b85c9e484799c59e to your computer and use it in GitHub Desktop.
Save benkn/cb00b85c9e484799c59e to your computer and use it in GitHub Desktop.
Date functions in Javascript
var DateUtil = {
/* Get the date for yesterday in YYYY-MM-DD format */
getYesterdayYMD : function() {
var d = new Date();
var m = d.getMonth() + 1;
var n = d.getDate() - 1;
var ds = d.getFullYear() + "-" + (m< 10? '0' + m : m) + "-" + (n<10 ? '0' + n : n);
return ds;
},
/* Get the date for today in YYYY-MM-DD format */
getDateYMD : function(d) {
var m = d.getMonth()+1;
var n = d.getDate();
var ds = d.getFullYear() + "-" + (m<10 ? '0' + m : m) + "-" + (n<10 ? '0' + n : n);
return ds;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment