0

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.

1
  • 1
    m/d/Y H:i:s and d/m/Y H:i:s.... upper-case H for 24-hr clock Commented Oct 19, 2015 at 22:43

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.