Re: Strtotime returns 02/09/2008 for "next Saturday"....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 31/01/2008, Mike Morton <mike@xxxxxxxxxxxx> wrote:
>
> Ya - the other server is 4.4.7
>
> However - this does not seem to be the problem necessarily:
>
> print date("m/d/Y",strtotime("next saturday"));
> 02/09/2008
>
> print date("m/d/Y",strtotime("next sunday"));
> 02/10/2008
>
> print date("m/d/Y",strtotime("next monday"));
> 02/11/2008
>
> print date("m/d/Y",strtotime("next tuesday"));
> 02/12/2008
>
> print date("m/d/Y",strtotime("next wednesday"));
> 02/13/2008
>
> print date("m/d/Y",strtotime("next thursday"));
> 02/07/2008
>
> So from today to next Thursday, the dates are all 1 week off....?
>
> On 1/31/08 11:03 AM, "Tom Chubb" <tomchubb@xxxxxxxxx> wrote:
>
> > On 31/01/2008, Mike Morton <mike@xxxxxxxxxxxx> wrote:
> >>
> >> I have been using:
> >>
> >> $nextSaturday= date("m/d/Y",strtotime("next saturday"));
> >>
> >> For months long time now with out problems, but in the last two days,
> it
> >> went kind of funky.  It is now returning:
> >>
> >> 02/09/2008 instead of the expected 02/02/2008.  I have tried the same
> code
> >> on another server and different version of PHP,and it works ok.
> >>
> >> More info:
> >>
> >> Shell date: Thu Jan 31 09:44:50 EST 2008
> >> echo date("Y-m-d g:i A T", time()); = 2008-01-31 10:00 AM EST
> >> echo date("Y-m-d g:i A T", strtotime("next saturday")); = 2008-02-09
> 12:00
> >> AM EST
> >>
> >> version: 4.3.9  (highest version we can have at the moment)
> >>
> >> I could not find this in the known bugs from this version....
> >>
> >> So - is this something that is server or version specific?
> >>
> >> TIA!
> >>
> >> --
> >> Cheers
> >>
> >> Mike Morton
> >>
> >> ****************************************************
> >> *
> >> * Tel: 905-465-1263
> >> * Email: mike@xxxxxxxxxxxx
> >> *
> >> ****************************************************
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> > The manual says:
> > *Warning*
> >
> > In PHP versions prior to 4.4.0, *"next"* is incorrectly computed as +2.
> A
> > typical solution to this is to use *"+1"*.
> >
> > Dunno if that helps you out? Is the other server > 4.4.0?
> > http://uk3.php.net/strtotime
>
> --
> Cheers
>
> Mike Morton
>
> ****************************************************
> *
> * Tel: 905-465-1263
> * Email: mike@xxxxxxxxxxxx
> *
> ****************************************************
>
>
>
> An example that may help:

when using strtotime("wednesday"), you will get different results whether
you ask before or after wednesday, since strtotime always looks ahead to the
*next* weekday.

strtotime() does not seem to support forms like "this wednesday", "wednesday
this week", etc.

the following function addresses this by always returns the same specific
weekday (1st argument) within the *same* week as a particular date (2nd
argument).

function weekday($day="", $now="") {

  $now = $now ? $now : "now";
  $day = $day ? $day : "now";

  $rel = date("N", strtotime($day)) - date("N");

  $time = strtotime("$rel days", strtotime($now));

  return date("Y-m-d", $time);

}

example use:

weekday("wednesday"); // returns wednesday of this week
weekday("monday, "-1 week"); // return monday the in previous week

ps! the ? : statements are included because strtotime("") without gives 1
january 1970 rather than the current time which in my opinion would be more
intuitive...

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux