Posted By

withremote on 06/11/09


Tagged

DateTime


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wilser


Change MySql DATETIME into something more friendly


 / Published in: PHP
 

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

  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
Posted By: stephan on June 18, 2009

I used to to it that way as well until I realised that php can handle it much much better and more efficient.

echo date('m/d/Y H:m A',strtotime($mySQLDateTime);

So what you do in 15 lines I did in 1.

You need to login to post a comment.