php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18281 strtotime incorrectly evaluates AM/PM
Submitted: 2002-07-11 13:39 UTC Modified: 2002-07-11 15:15 UTC
From: mwilmes at avc dot edu Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.2.1 OS: Win 2K
Private report: No CVE-ID: None
 [2002-07-11 13:39 UTC] mwilmes at avc dot edu
I'm writing a timeclock for work, but have a problem processing 12 hour times:

--Script--
<?php
$T=array('05:00 PM','05:00PM','5:00 PM','5:00PM');
foreach ($T as $TIME)
{
  echo $TIME.'<br>';
  echo strtotime($TIME).'<br>';
  echo date("Y-m-d h:i:s",strtotime($TIME)).'<br><br>';
}
?>

--Output--
05:00 PM
1026432000
2002-07-11 05:00:00

05:00PM
1026432000
2002-07-11 05:00:00

5:00 PM
1026432000
2002-07-11 05:00:00

5:00PM
1026432000
2002-07-11 05:00:00

I've compiled PHP 4.2.1 for Apache 2.0.39 with SSLOpen 0.9.7 beta 2.  PHP is installed as a module.

Is it me or my box?
Thanks in advance,
Mike Wilmes

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-11 15:15 UTC] sniper@php.net
Your script is buggy. Read this manual page a bit more carefully: http://www.php.net/manual/en/function.date.php

h - hour, 12-hour format; i.e. "01" to "12"                  H - hour, 24-hour format; i.e. "00" to "23" 


 [2010-08-18 20:55 UTC] sniper at svencoop dot com
NOT BOGUS.

sniper@php.net, you missed his point entirely. His code is correct.

strotime() doesn't account for the 12 hour format being passed in, that's the 
issue. The time string returned is passed to date(), which outputs correctly 
strtotime()'s invalid conversion of the text string.

The issue is when a 12 hour format time like 5:00 PM is passed in, it always 
returns with 5:00 AM.

He is obviously using h for the date output, but that's not important what-so-
ever. This should be fixed.
 [2010-08-18 21:51 UTC] jedinewrepublic at netscape dot net
I think you jumped the gun, 05:00:00 is correct but the AM / PM was ommitted from 
the output
 [2010-08-18 21:53 UTC] sniper at svencoop dot com
Oops, disregard.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC