jonsamwell Posted January 9, 2009 Share Posted January 9, 2009 Hi, mysql stores date as Y-m-d H:i:s. How would i change the format of the string i get back after a sql query so that the format is "d-m-Y H:i:s". I have tried: $date = date($row['previous_login']); $date = date_format($date, "d-m-Y G:i:s"); but i get back an error. Any ideas? Thanks Jon Link to comment https://forums.phpfreaks.com/topic/140123-change-date-format-with-data-back-from-mysql/ Share on other sites More sharing options...
vbnullchar Posted January 9, 2009 Share Posted January 9, 2009 $date_s = strtotime($row['previous_login']); $date = date_format($date_s, "d-m-Y G:i:s"); Link to comment https://forums.phpfreaks.com/topic/140123-change-date-format-with-data-back-from-mysql/#findComment-733157 Share on other sites More sharing options...
jonsamwell Posted January 9, 2009 Author Share Posted January 9, 2009 $date_s = strtotime($row['previous_login']); $date = date_format($date_s, "d-m-Y G:i:s"); thanks for replying it throws back the error "Warning: date_format() expects parameter 1 to be DateTime, integer given in C:\wamp\www\SRC\PHP\db.php on line 301" any ideas Link to comment https://forums.phpfreaks.com/topic/140123-change-date-format-with-data-back-from-mysql/#findComment-733167 Share on other sites More sharing options...
vbnullchar Posted January 9, 2009 Share Posted January 9, 2009 sorry here it is, use date only. $date_s = strtotime($row['previous_login']); $date = date($date_s, "d-m-Y G:i:s"); Link to comment https://forums.phpfreaks.com/topic/140123-change-date-format-with-data-back-from-mysql/#findComment-733169 Share on other sites More sharing options...
jonsamwell Posted January 9, 2009 Author Share Posted January 9, 2009 sorry here it is, use date only. $date_s = strtotime($row['previous_login']); $date = date($date_s, "d-m-Y G:i:s"); Cool thanks alot it worked when i changed the order of parameters around with the dat() funt Link to comment https://forums.phpfreaks.com/topic/140123-change-date-format-with-data-back-from-mysql/#findComment-733173 Share on other sites More sharing options...
jonsamwell Posted January 9, 2009 Author Share Posted January 9, 2009 Great thanks! This is the final code that worked $date_s = strtotime($row['previous_login']); $date = date("d-m-Y G:i:s", $date_s); Link to comment https://forums.phpfreaks.com/topic/140123-change-date-format-with-data-back-from-mysql/#findComment-733174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.