Skip to content

Instantly share code, notes, and snippets.

@ryanmerritt
Created September 18, 2012 10:22
Show Gist options
  • Save ryanmerritt/3742461 to your computer and use it in GitHub Desktop.
Save ryanmerritt/3742461 to your computer and use it in GitHub Desktop.
PHP MySQL DATETIME Conversion Code for both inserting into and displaying from a mysql db.
<?php
// DATE/TIME Manipulation for dates from php to mysql and back again
// get time and date right now for inserting datetime into mysql
// the field in the db should be set as a mysql "datetime" field type
// First - set the local timezone
date_default_timezone_set('America/New_York')
// use this in a hidden form field to insert the time into db record
echo date('Y-m-d H:i:s',time());
// this formats a mysql datetime field result from a recordset into your preferred format
echo date("m/d/Y", strtotime($recordset['DATE']));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment