Created
February 27, 2014 23:19
-
-
Save jphase/9261824 to your computer and use it in GitHub Desktop.
Add ymd prototype to Date object to format javascript dates as Y-m-d
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
// Prototype for js Date object to format in Y-m-d | |
Date.prototype.ymd = function() { | |
var yyyy = this.getFullYear().toString(); | |
var mm = (this.getMonth()+1).toString(); | |
var dd = this.getDate().toString(); | |
return yyyy + '-' + (mm[1] ? mm : '0' + mm[0]) + '-' + (dd[1] ? dd : '0' + dd[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment