Advertisement
gilzow

AP Style dates

Nov 5th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. /**
  2.  * converts Date to AP Style date
  3.  * @param string $strDate
  4.  * @return string
  5.  */
  6. function ap_date($strDate) {
  7.     $strAPDatePattern = '%s %d, %d';
  8.     $intDate = strtotime($strDate);
  9.  
  10.     $strMonth = date('F',$intDate);
  11.     $intDay = date('j',$intDate);
  12.     $intYear = date('Y',$intDate);
  13.  
  14.     if(strlen($strMonth) > 5){ //stoopid september... grumble, grumble
  15.         if($strMonth == 'September'){
  16.             $intTruncLen = 4;
  17.         } else {
  18.             $intTruncLen = 3;
  19.         }
  20.  
  21.         $strMonth = substr($strMonth,0,$intTruncLen) . '.';
  22.     }
  23.  
  24.     return sprintf($strAPDatePattern,$strMonth,$intDay,$intYear);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement