Convert date/time into a readable format.


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.