PHP srttotime request for "PM" returns "AM"?

pQL7CmRP2i4 :

I am trying to test whether the current time is past noon on the current day, but a call to strtotime does not return the value I expect.

CODE

$time=strtotime("12:00 PM TODAY");
echo date('h:i:s A',$time);

OUTPUT

12:00:00 AM
aynber :

You have it in the wrong order. You need the day, then the time:

$time=strtotime("TODAY 12:00 PM");
echo date('Y-m-d H:i:s', $time); // 2020-02-25 12:00:00

See https://www.php.net/manual/en/datetime.formats.relative.php :

Relative statements are always processed after non-relative statements. This makes "+1 week july 2008" and "july 2008 +1 week" equivalent.

Exceptions to this rule are: "yesterday", "midnight", "today", "noon" and "tomorrow". Note that "tomorrow 11:00" and "11:00 tomorrow" are different. Considering today's date of "July 23rd, 2008" the first one produces "2008-07-24 11:00" where as the second one produces "2008-07-24 00:00". The reason for this is that those five statements directly influence the current time.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11497&siteId=1