Skip to content

Instantly share code, notes, and snippets.

@melbourne2991
Created July 10, 2014 00:17
Show Gist options
  • Save melbourne2991/da7b60b544e35c4ac153 to your computer and use it in GitHub Desktop.
Save melbourne2991/da7b60b544e35c4ac153 to your computer and use it in GitHub Desktop.
Converts date objects to YYYY-MM-DD
// Converts date object to yyyy-mm-dd
var convertDateToString = function(timestamp) {
var yyyy = timestamp.getFullYear();
var mm = timestamp.getMonth();
var dd = timestamp.getDate();
if(mm < 10) mm = '0' + mm.toString();
if(dd < 10) dd = '0' + dd.toString();
yyyy = yyyy.toString();
return yyyy + '-' + mm + '-' + dd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment