php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15194 date("m-d-y H:m:s", $timestamp) doesn't jive with system time
Submitted: 2002-01-24 00:19 UTC Modified: 2002-07-03 16:38 UTC
Votes:7
Avg. Score:5.0 ± 0.0
Reproduced:7 of 7 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: emetsger at jhu dot edu Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.2.1 OS: Solaris 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: emetsger at jhu dot edu
New email:
PHP Version: OS:

 

 [2002-01-24 00:19 UTC] emetsger at jhu dot edu
calling date("m-d-y H:m:s", $timestamp) doesn't always produce the correct system date.

The linked page and source demonstrate this problem.

The date is gathered from three different sources on the system: the date command, the date within mysql, and the php time() function call.

The three different sources all produce identical timestamps.  However, when I call the date() function with the above timestamp, the system date will not match the formatted date returned by date().

I saw this problem orginally in my 4.0.6 install, and just upgraded to 4.1.1 and my test page still exhibits the same behavior.

The page is located at: http://esm.mse.jhu.edu/cms/test/testdate.php
The source is at:
http://esm.mse.jhu.edu/cms/test/testdate.phps
My phpinfo page is at:
http://esm.mse.jhu.edu/cms/test/index.php

Thanks for taking a look!

Elliot Metsger

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-02 16:26 UTC] gg3po at hotmail dot com
Addionally, I've descovered that when PHP gets a timestamp from a UNIX file that was created/modified on the first
day of any month ( use ls -al from the command line to verify the actual date modified), PHP returns the mday (in the case of getdate()), or "d" (in the case of date()) as being the last day of the PREVIOUS month + 1 day, instead of returning 1, which is the actual day of modification/creation.  It doesn't even try to claim it's day 0. It just invents an imaginary day for the previous month and returns that.  It also gets the "m" (date()),  or 'mon' and 'month'  (getdate()) values wrong, returning them as those of the previous month.  Try using date("m - d", $timestamp_from_unix_file); if you don't believe me.

BTW, the $timestamp_from_unix_file in the example above, actually has to be FROM a REAL unix file, not a PHP
generated unix timestamp. Use filemtime($filename) to get it.
 [2002-07-02 16:33 UTC] eru@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately your version of PHP is too old -- the problem
might already be fixed. Please download a new PHP
version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 [2002-07-03 12:45 UTC] emetsger at jhu dot edu
Please do not call this bug bogus.  I submitted this bug in 2001, and since then I have upgraded to 4.2.1 as listed in my phpinfo() page.

The test links have been updated to work properly, and the bug still exhibits the buggy behavior.
 [2002-07-03 12:48 UTC] emetsger at jhu dot edu
Changed status back to Open.
 [2002-07-03 12:53 UTC] eru@php.net
That was the purpose of my bugusifying of the report, to get an update from you. Please take a look at the message ;-)
Anyway, your pages only yield a 403 Forbidden, so please grant access, so that I can verify the bug. :-)

Thanks for helping!

 [2002-07-03 14:10 UTC] eru@php.net
Sorry, but I couldn't reproduce this on my 5.8 system.

I did
touch -am -t 200203011200 timestamp.dat

timestamp.php is
<pre>
<?php
$timestamp = filemtime( "timestamp.dat" );
var_dump( $timestamp );
var_dump( date( "Y.m.d" , $timestamp ) );
var_dump( getdate( $timestamp ) );
?>
</pre>

output is
int(1014980400)
string(10) "2002.03.01"
array(11) {
  ["seconds"]=>
  int(0)
  ["minutes"]=>
  int(0)
  ["hours"]=>
  int(12)
  ["mday"]=>
  int(1)
  ["wday"]=>
  int(5)
  ["mon"]=>
  int(3)
  ["year"]=>
  int(2002)
  ["yday"]=>
  int(59)
  ["weekday"]=>
  string(6) "Friday"
  ["month"]=>
  string(5) "March"
  [0]=>
  int(1014980400)
}

so, everything looks ok by me.

As I'm still not able to see your code, are you _sure_ that you're not making any errors?

 [2002-07-03 16:12 UTC] emetsger at jhu dot edu
Please accept sincere apologies: I did not fully read your response.  The pages should be open now (I have no real way to test them).

Thank you again!
 [2002-07-03 16:38 UTC] eru@php.net
Sorry to disappoint you, I should've payed more attention to the summary of this bug, as the error is already apparent there.
The minutes are "i", not "m" as in your example. Not wonder, you're getting false results :-)

Bogusifying again.

P.S. the funny thing is, you're using the right format in your last line of code *grin*. I hope you see the humor in it.
 [2003-04-04 03:55 UTC] harry at nijvink dot nl
In this function you use the month as minutes. Try this:
date("m-d-y H:i:s", $timestamp) 

Harry van de Hoef
Nijvink Automatisering
http://www.nijvink.nl
 [2003-06-19 22:43 UTC] ocean at justocean dot com
you are foolish!!!

date("m-d-y H:m:s") is a error!

should be date("m-d-y H:i:s")!!!!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 05:01:30 2024 UTC