-
-
Save robsmith1776/0ae0a1ec505f54fc7365267eb5c69eee to your computer and use it in GitHub Desktop.
Javascript Date to Postgres-acceptable format
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
// Convert Javascript date to Pg YYYY MM DD HH MI SS | |
function pgFormatDate(date) { | |
/* Via http://stackoverflow.com/questions/3605214/javascript-add-leading-zeroes-to-date */ | |
function zeroPad(d) { | |
return ("0" + d).slice(-2) | |
} | |
var parsed = new Date(date) | |
return [parsed.getUTCFullYear(), zeroPad(parsed.getMonth() + 1), zeroPad(parsed.getDate()), zeroPad(parsed.getHours()), zeroPad(parsed.getMinutes()), zeroPad(parsed.getSeconds())].join(" "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment