Answer the question
In order to leave comments, you need to log in
How to fix error in Call to a member function format() on a non-object?
Hello. After moving the site to another hosting, the following code does not work:
$Stroke = $Year.'-'.$Month.'-'.$Day.' '.$Hours.':'.$Minutes.':'.$Seconds;
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, $Stroke);
if ($Format == ''){
$Format = 'd.m.Y H:i:s';
}
$result = $date->format($Format);
Answer the question
In order to leave comments, you need to log in
you have DateTime::createFromFormat($format, $Stroke); returns false
- check the contents of $Stroke
- check the time zone settings
See what the DateTime::getLastErrors() function returns.
Alternatively, the time zone may not be set on the server - try using the full format of the DateTime::createFromFormat function :
$date = DateTime::createFromFormat($format, $Stroke, new DateTimeZone('Europe/Moscow'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question