Skip to content

Instantly share code, notes, and snippets.

@poloey
Created February 25, 2018 19:26
Show Gist options
  • Save poloey/cbec3898bb0941605ed16375c64fdfae to your computer and use it in GitHub Desktop.
Save poloey/cbec3898bb0941605ed16375c64fdfae to your computer and use it in GitHub Desktop.
mysql_date_format_from_javascript
function str_pad(n) {
return String("00" + n).slice(-2);
}
var dateObj = new Date();
var month = str_pad( dateObj.getUTCMonth() + 1);
var day = str_pad(dateObj.getUTCDate() + 1);
var year = dateObj.getUTCFullYear();
newdate = year + "-" + month + "-" + day;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment