php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16536 Give me inconsisten results
Submitted: 2002-04-10 16:43 UTC Modified: 2002-04-11 17:39 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: james at jimijon dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.1.2 OS: mac os x
Private report: No CVE-ID: None
 [2002-04-10 16:43 UTC] james at jimijon dot com
#get the numeric sunday
                $today_var = getdate();
                $today_sec = mktime(0,0,0,date("m"),date("d"),date("Y"));
                $offset = $today_var[wday] * 86400 ;
                $first_day = $today_sec - $offset;
                $this_week_first_date = date("ymd", $first_day);
                $path=$this_week_first_date;

this just won't get me Sunday this week.. 020407
suddenly at midnight on Monday the 8th it went to 06, this has been running fine for many many weeks now.

Help

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-11 05:35 UTC] hholzgra@php.net
daylight saving time?!

use mktime(12,0,0,...) if you are interested in the date only
 [2002-04-11 11:36 UTC] james at jimijon dot com
No, just trying to get a consistently working numeric date for the Sunday of that week.  yymmdd

Though a previos algorithm I had:
echo "last sunday: ".date("ymd", mktime(0,0,0,$mnth,$dy-date("w",mktime(0,0,0,$mnth,$dy,$yr)),$yr))."<br

is working this week properly, but has in the past worked inproperly.. there is something really goofy going on with the date math in php.

Anyone have a ultra reliable Sunday of the Week algorithm?
 [2002-04-11 12:59 UTC] hholzgra@php.net
Guess it worked last week only due to the daylight saving switch which compensated an off-by-one error in your code.

*Every* piece of code that uses mktime(0,0,0,...) and
addition or subtraction of multiples of 86400 has to
check for daylight saving time switches or use the optional 7th parameter to mktime() to be correct

this database is full of user bugs related to this issue
 [2002-04-11 14:28 UTC] james at jimijon dot com
$today_var = getdate();
                        $today_sec = mktime(0,0,0,date("m"),date("d"),date("Y"),1);
                        $offset = ($today_var['wday']-0) * 86400 ;
                        $first_day = $today_sec - $offset;
                        $this_week_first_date = date("ymd", $first_day);
                        $path=$this_week_first_date;


Still gives the wrong result.. Doesn't anybody have a reliable piece of code to Get the Sunday of the current week, this week it should be the 7th not the 6th!

Now this week however this code works:
date("ymd", mktime(0,0,0,$mnth,$dy-date("w",mktime(0,0,0,$mnth,$dy,$yr)),$yr))

What gives? A real piece of code that works reliably still needed for me and for sure everybody.
 [2002-04-11 14:34 UTC] hholzgra@php.net
The bug system is not the appropriate forum for asking support
questions. For a list of a range of more appropriate places to ask
for help using PHP, please visit http://www.php.net/support.php


 [2002-04-11 15:21 UTC] james at jimijon dot com
OK - my apologies, I have wrapped up into one posting both a bug and a support issue. I will post on the support area, but, I do believe this is a bug.
 [2002-04-11 16:42 UTC] derick@php.net
ya ya, lets keep it closed now.
 [2002-04-11 17:39 UTC] hholzgra@php.net
Question one: 
When does Daylight Saving Time switch happen 
in your country aka. in whatever is configured
on your system?

Question two:
have you at least *tried* mktime(12,0,0,...
to have your calculations noon-based instead 
of midnight based?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 11:01:31 2024 UTC