Posted By

xtheonex on 01/27/09


Tagged

php


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

fackz
jeremyhcobb
umang_nine
jealousy
tapdrup


Convert date/time into a readable format.


 / Published in: PHP
 

A quick, usefull function which i use to convert a date/time string pulled from MySQL, into a readable format.

  1. function dateConvert($old_date, $layout) {
  2. $date = ereg_replace('[^0-9]', '', $old_date);
  3. $date_year = substr($old_date,0,4);
  4. $date_month = substr($old_date,5,2);
  5. $date_day = substr($old_date,8,2);
  6. $date_hour = substr($old_date,11,2);
  7. $date_minute = substr($old_date,14,2);
  8. $date_second = substr($old_date,17,2);
  9. $new_date = date($layout, mktime($date_hour, $date_minute, $date_second, $date_month, $date_day, $date_year));
  10. return $new_date;
  11. }

Report this snippet  

You need to login to post a comment.