Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Created July 18, 2013 07:18
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 Sleavely/6027328 to your computer and use it in GitHub Desktop.
Save Sleavely/6027328 to your computer and use it in GitHub Desktop.
<?php
function correctYYMMDD($input){
$input = substr($input, 0, 6);
//is it already in correct format?
if(preg_match('/[0-9][0-9](1[0-2]|0[1-9])([0-2][0-9]|3[01])/', $input)) return $input;
//let's reverse it.
$rev = array();
$rev['yy'] = substr($input, 4, 2);
$rev['mm'] = substr($input, 2, 2);
$rev['dd'] = substr($input, 0, 2);
return $rev['yy'].$rev['mm'].$rev['dd'];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment