0

PHP time format generate different results when spaces included

 date('h:i A',strtotime('05:45 AM')); //05:45AM
 date('h:i A',strtotime('05 : 45 AM')); // 01:00 AM

Here is the result

Spaces works in older version of PHP and it is failing in PHP Version above 5.0.5; I wanted to check why this is not allowed with new version

6
  • 5
    Spaces are not valid in time formats so if you use them you should expect incorrect results. Commented May 22, 2014 at 13:40
  • 1
    What is your question? Commented May 22, 2014 at 13:41
  • You could however strip out the spaces and then parse the time using strtotime(). Commented May 22, 2014 at 13:41
  • because it is not valid time for PHP.It will always show the same time 01:00 AM whatever you enter with space Commented May 22, 2014 at 13:42
  • I noted different results showing in time.I wanted confirm this is not a bug in newer version Commented May 22, 2014 at 13:53

1 Answer 1

1

As stated in the comments, its not a valid time format with the spaces.

Check this resource for strtotime: https://www.php.net/manual/en/function.strtotime.php

And also check this page for date/time formats: https://www.php.net/manual/en/datetime.formats.php

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.