Bug 125656 - PHP Date Functions not working properly
PHP Date Functions not working properly
Status: CLOSED WONTFIX
Product: Fedora
Classification: Fedora
Component: php (Show other bugs)
1
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Joe Orton
David Lawrence
http://www.swingular.com/timetest.php
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-06-09 15:13 EDT by Robert Frew
Modified: 2007-11-30 17:10 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-06-21 11:47:07 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Robert Frew 2004-06-09 15:13:17 EDT
is a dating site that relies on the date functions heavily for 
converting timestamps to ages and vice versa.  Up until the latest 
update, everything worked correctly (for 2 plus years).  I did 
nothing to the code or system except for the update.

Now, when converting a timestamp using the date() function for any 
date beyond the month of june (year doesn't matter), it converts it 
to a day earlier than what it actually is. See the example at the 
included URL.

But if converting a date from january to june, it converts correctly.

Also, if I try to get the age using a tJust updated my Fedora Core 1 
to the latest releases using Yum.  My website imestamp for a birthday 
of june 9, 1974 and todays date is june 9th, it shows the correct age 
of 30.  But if my birthday is june 11, 1974, it still says my age is 
30.
Again, see the example at the included URL.

1. Timestamp of 156146400 should equal 12/13/1974.
2. <?php date("m/d/Y", 156146400); //shows 12/12/1974. ?>
3. The following code converts a timestamp to an age:
<?php
$curtime = time();
$ageunix = $curtime - 140162400;
$age = floor($ageunix / (365 * 24 * 60 * 60));
$age2 = $ageunix / (365 * 24 * 60 * 60);
echo "Age: ".$age." <font color=\"red\"><-- Wrong, should be 
29</font>";
echo "<br>";
echo "Age without Floor ".$age2;
echo "<br>";
echo "<br>";
echo "Date: ".date("m/d/Y", 140162400); // 140162400 = June 11, 1974, 
this converts correctly
?>

Actual Results: Date of 12/12/1974 and age of 30
Expected Results: Date of 12/13/1974 and age of 29
Comment 1 Robert Frew 2004-06-09 15:16:18 EDT
Correction:

Just updated my Fedora Core 1 to the latest releases using Yum.  My 
website is a dating site that relies on the date functions heavily 
for 
converting timestamps to ages and vice versa.  Up until the latest 
update, everything worked correctly (for 2 plus years).  I did 
nothing to the code or system except for the update.

Now, when converting a timestamp using the date() function for any 
date beyond the month of june (year doesn't matter), it converts it 
to a day earlier than what it actually is. See the example at the 
included URL.

But if converting a date from january to june, it converts correctly.

Also, if I try to get the age using a timestamp for a birthday 
of june 9, 1974 and todays date is june 9th, it shows the correct age 
of 30.  But if my birthday is june 11, 1974, it still says my age is 
30.
Comment 2 Joe Orton 2004-06-09 15:19:35 EDT
Please confirm the version of PHP in use:

$ rpm -q php
Comment 3 Robert Frew 2004-06-09 15:46:24 EDT
php-4.3.6-1.3
Comment 4 Robert Frew 2004-06-09 15:47:35 EDT
I found a new age converting function that seems to convert the age 
correctly now but the date() function still has an error.

function GetAge($dob)
{
	$date_of_birth = date("Ymd", $dob);
	$now = date("Ymd", time());
	$age = (int) (($now - $date_of_birth)/10000);
	return $age;
}
Comment 5 Robert Frew 2004-06-09 16:22:39 EDT
Ok, supposedly, Redhat versions since 7.3 do not support negative 
timestamps in glibc.  This prompted me to use a library that takes 
over negative timestamp conversions.  I'm assuming the timestamp of 0 
equals 12/31/1969.  Prior to the update, I think the timestamp of 0 
may have been 01/01/1970.  Using the library that was basing 0 off 
the latter, the calculations were one day off.

I found an updated library that calculates the negative timestamps 
correctly and this seems to have fixed the problem.  You can get this 
library here:  http://php.weblogs.com/adodb_date_time_library
Comment 6 Joe Orton 2004-06-10 05:30:36 EDT
I can't reproduce the original problem you reported here:

<?php date("m/d/Y", 156146400); //shows 12/12/1974. ?>

what $TZ do you have?  Maybe try something like this:

$ echo '<?php print date("m/d/Y U", 156146400) . "\n"; ?>' | TZ=GMT php -q


Comment 7 Robert Scheck 2004-07-14 07:52:12 EDT
Namesake, I'm able to reproduce the same problem using php 4.3.8, my 
timezone is CEST for this example:

--- snipp ---
3. The following code converts a timestamp to an age: Age: 30 <-- Wrong, should be 29
Age without Floor 30.112983479198

Date: 06/11/1974
--- snapp ---

But Joe's example works, if the TZ is set to GMT...

--- snipp ---
# echo '<?php print date("m/d/Y U", 156146400) . "\n"; ?>' | TZ=GMT php -q
12/13/1974 156146400
# 
--- snapp ---

...so I think it's a PHP timezone problem?!
Comment 8 Joe Orton 2005-06-21 11:47:07 EDT
[This is a mass bug update]

Fedora Core 1 is now maintained by the Fedora Legacy project for
security updates only. If this problem is a security issue, please
reopen and reassign to the Fedora Legacy product. If it is not a
security issue and hasn't been resolved in the current FC3 or FC4 updates,
reopen and change the version to match.

Note You need to log in before you can comment on or make changes to this bug.