Created
September 18, 2012 10:22
-
-
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.
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
<?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