Reputation: 4610
I'm trying to convert a timestamp that's stored in a database from the MM/DD/YYYY HH:MM:SS
format to DD/MM/YYYY HH:MM:SS
format but I'm getting an error
"PHP Fatal error: Call to a member function format() on a non-object"
Here's my code:
date_default_timezone_set('Australia/Sydney');
$clientTimestamp = '10/25/2015 21:22:47';
$date = DateTime::createFromFormat("m/d/Y h:i:s", $clientTimestamp );
$clientTimestampAU = $date->format("d/m/Y h:i:s");
I'm getting the error on the last line - I can't work out what the issue is here.
Upvotes: 0
Views: 25
Reputation: 699
The hour parameter is H
and not h
So, instead of
date_default_timezone_set('Australia/Sydney');
$clientTimestamp = '10/25/2015 21:22:47';
$date = DateTime::createFromFormat("m/d/Y h:i:s", $clientTimestamp );
$clientTimestampAU = $date->format("d/m/Y h:i:s");
Make it
date_default_timezone_set('Australia/Sydney');
$clientTimestamp = '10/25/2015 21:22:47';
$date = DateTime::createFromFormat("m/d/Y H:i:s", $clientTimestamp );
$clientTimestampAU = $date->format("d/m/Y H:i:s");
Upvotes: 1