Skip to content

Instantly share code, notes, and snippets.

@atomize
Created March 29, 2013 16:06
Show Gist options
  • Save atomize/5271768 to your computer and use it in GitHub Desktop.
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
<?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