Created
March 29, 2013 16:06
-
-
Save atomize/5271768 to your computer and use it in GitHub Desktop.
I use this to take dates formatted like 'Mon Apr 1 00:12:23 2013' and turn them in to '04/01/2013' in PHP
This file contains hidden or 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 | |
$time = "Mon Apr 1 00:00:00 2013"; // Has a rando extra space for example purposes | |
$pattern = '/\s\s+/'; // fix that rando extra space with regex and preg_replace() | |
$str = preg_replace($pattern, ' ', $time); | |
$str = strtotime($str); // convert the time to UNIX time using built-in strtotime() function of PHP | |
$str = date('m/d/Y', $str); // use date() to convert accurate UNIX time to desired format | |
echo "\n".$str."\n"; // big pimpin' | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment