Skip to content

Instantly share code, notes, and snippets.

@jphase
Created February 27, 2014 23:19
Show Gist options
  • Save jphase/9261824 to your computer and use it in GitHub Desktop.
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
// 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