Created
July 13, 2014 22:55
-
-
Save benkn/cb00b85c9e484799c59e to your computer and use it in GitHub Desktop.
Date functions in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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