How to set MySQL date from a result set to a PHP datetime object?

i am trying to set the date and time (DateTime stored in mysql database) to a php DateTime object, one way is to override the class some how to make that happen, but is there any easier way than that?e. g. $date = new DateTime();$date->setDate($mysql_resultset[‘date_time’]);and then format that date according and display it.

One thought on “How to set MySQL date from a result set to a PHP datetime object?”

  1. $date = date(‘Y-m-d’,strtotime($date_from_mysql));you can use any date formatting as first parameter, second is date string.

Leave a Reply

Your email address will not be published. Required fields are marked *