Posts

Showing posts with the label date-conversion

Convert one date format into another in PHP

Convert one date format into another in PHP Is there a simple way to convert one date format into another date format in PHP? I have this: $old_date = date('y-m-d-h-i-s'); // works $middle = strtotime($old_date); // returns bool(false) $new_date = date('Y-m-d H:i:s', $middle); // returns 1970-01-01 00:00:00 But I'd of course like it to return a current date rather than the crack 'o dawn. What am I doing wrong? tech-blog.maddyzone.com/php/type-date-convert-php very nice article – Rituraj ratan Sep 27 '14 at 7:17 14 Answers 14 The second parameter to date() needs to be a proper timestamp (seconds since January 1, 1970). You are passing a string, which date() can't recognize. date() You can use strto...