Change MySql DATETIME into something more friendly


/ Published in: PHP
Save to your folder(s)

converts DateTIME, like 2009-06-11 10:30:40 into 06/11/2009 10:30 AM


Copy this code and paste it in your HTML
  1. function readableDateTime($mySQLDateTime) {
  2. list($date, $time) = split(' ',$mySQLDateTime);
  3.  
  4. $d = explode("-", $date);
  5. $t = explode(":", $time);
  6.  
  7. $datefixed = $d[1]."/".$d[2]."/".$d[0];
  8. if ($t[0] <= 12) {
  9. $timefix = $t[0].":".$t[1]." AM";
  10. }
  11. if ($t[0] > 12) {
  12. $timefix = ($t[0] - 12 ).":".$t[1]." PM";
  13. }
  14. echo $datefixed." ".$timefix;
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.