Answers for "object of class datetime could not be converted to int"

0

object of class datetime could not be converted to int

Because $newDate is an object of type DateTime, not a string. The documentation is explicit:

Returns new DateTime object formatted according to the specified format.

If you want to convert from a string to DateTime back to string to change the format, call DateTime::format at the end to get a formatted string out of your DateTime.

$newDate = DateTime::createFromFormat("l dS F Y", $dateFromDB);
$newDate = $newDate->format('d/m/Y'); // for example
Posted by: Guest on March-09-2021

Code answers related to "object of class datetime could not be converted to int"

Browse Popular Code Answers by Language