php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8716 Error in date("j", <time>) or getdate(<time>) function
Submitted: 2001-01-15 11:55 UTC Modified: 2001-01-15 12:08 UTC
From: ageorgou at filmnet dot gr Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.0.3pl1 OS: RedHat Linux 7.0
Private report: No CVE-ID: None
 [2001-01-15 11:55 UTC] ageorgou at filmnet dot gr
<?
echo "date function gives wrong day for dates between 28 and 31 of October on any year\n";

$daySeconds = 86400;
$time = 1004216400;
echo "Day in 28 of October is " . date("j", $time) . "<BR>\n";
$time += $daySeconds;
echo "Day in 29 of October is " . date("j", $time) . "<BR>\n";
$time += $daySeconds;
echo "Day in 30 of October is " . date("j", $time) . "<BR>\n";
$time += $daySeconds;
echo "Day in 31 of October is " . date("j", $time) . "<BR>\n";
?>

Configure Line is
./configure' '--prefix=/usr' '--with-config-file-path=/etc' '--disable-debug' '--enable-pic' '--enable-shared' '--enable-inline-optimization' '--with-apxs=/usr/sbin/apxs' '--with-exec-dir=/usr/bin' '--with-regex=system' '--with-gettext' '--with-gd=shared' '--with-jpeg-dir=/usr' '--with-png' '--with-zlib' '--with-db2' '--with-db3' '--with-gdbm' '--enable-debugger' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-yp' '--enable-ftp' '--without-mysql' '--without-oracle' '--without-oci8' '--with-openssl' '--with-xml'



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-15 12:08 UTC] rasmus@php.net
Your starting timestamp is wrong.  1004216400 is a timestamp for the 27th of October.   At least in my timezone.  You may be in a different timezone where this falls right around midnight so you think it is on the 28th, but then daylight savings time may throw you off.  If you are going to do math like this using timestamps pick a starting timestamp around noon so that the +-1 hour for daylight savings doesn't throw everything off on you.
 [2001-01-15 12:08 UTC] ageorgou at filmnet dot gr
date function doesn't give the same dates as it would expecte if we add the day seconds (86400) in a UNIX timestamp. I realised that these is because I didn't take any consideration of daylight time savings.

<?
$daySeconds = 86400;
$time = 1004216400;
echo "Day in 28 of October is " . date("j", $time) .
"<BR>\n";
$time += $daySeconds;
echo "Day in 29 of October is " . date("j", $time) .
"<BR>\n";
$time += $daySeconds;
echo "Day in 30 of October is " . date("j", $time) .
"<BR>\n";
$time += $daySeconds;
echo "Day in 31 of October is " . date("j", $time) .
"<BR>\n";
?>

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC