Skip to content

Instantly share code, notes, and snippets.

@hinch
Last active May 17, 2016 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hinch/7871334 to your computer and use it in GitHub Desktop.
Save hinch/7871334 to your computer and use it in GitHub Desktop.
PHP Date test
<?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