Last active
May 17, 2016 21:32
-
-
Save hinch/7871334 to your computer and use it in GitHub Desktop.
PHP Date test
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 | |
echo "OLD STYLE<br />"; | |
$input = "13/12/2013"; | |
echo $input."<br />"; | |
echo date( 'd/m/Y', strtotime( $input ) ); | |
echo "<hr />"; | |
$input = "13/12/2013 01:00:00"; | |
echo $input."<br />"; | |
echo date( 'd/m/Y H:i:s', strtotime( $input ) ); | |
echo "<hr />"; | |
$input = "13/12/2013"; | |
echo $input."<br />"; | |
echo date( 'Y-m-d', strtotime( $input ) ); | |
echo "NEW STYLE<br />"; | |
echo "<hr />"; | |
$input = "13/12/2013"; | |
$date = DateTime::createFromFormat('d/m/Y', $input); | |
echo $date->format('Y-m-d'); | |
echo "<hr />"; | |
$input = "13/12/2013 01:00:00"; | |
$date = DateTime::createFromFormat('d/m/Y H:i:s', $input); | |
echo $date->format('Y-m-d'); | |
echo "<hr />"; | |
$input = "13/12/2013"; | |
$date = DateTime::createFromFormat('d/m/Y', $input); | |
echo $date->format('m-d-Y'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment