PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

Réponse
 
LinkBack Outils de la discussion
Vieux 31/01/2008, 16h27   #1
Mike Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

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@gmail.com> wrote:

> On 31/01/2008, Mike Morton <mike@webtraxx.com> 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@webtraxx.com
>> *
>> ************************************************** **
>>
>> --
>> 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 s you out? Is the other server > 4.4.0?
> http://uk3.php.net/strtotime


--
Cheers

Mike Morton

************************************************** **
*
* Tel: 905-465-1263
* Email: mike@webtraxx.com
*
************************************************** **
  Réponse avec citation
Vieux 31/01/2008, 16h55   #2
Tom Chubb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

On 31/01/2008, Mike Morton <mike@webtraxx.com> 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@gmail.com> wrote:
>
> > On 31/01/2008, Mike Morton <mike@webtraxx.com> 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@webtraxx.com
> >> *
> >> ************************************************** **
> >>
> >> --
> >> 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 s you out? Is the other server > 4.4.0?
> > http://uk3.php.net/strtotime

>
> --
> Cheers
>
> Mike Morton
>
> ************************************************** **
> *
> * Tel: 905-465-1263
> * Email: mike@webtraxx.com
> *
> ************************************************** **
>
>
>
> An example that may :


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...

  Réponse avec citation
Vieux 31/01/2008, 17h57   #3
Richard Lynch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

Maybe it's just me, but I've never quite figured out what people mean
when they say "next Saturday"...

Do they mean the next one coming up?

Or do they mean that there's "this Saturday" coming up and "next
Saturday" the one after that?

And if I can't figure it out, why would you expect PHP to figure it out?

:-)

On Thu, January 31, 2008 10:27 am, Mike Morton 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@gmail.com> wrote:
>
>> On 31/01/2008, Mike Morton <mike@webtraxx.com> 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@webtraxx.com
>>> *
>>> ************************************************** **
>>>
>>> --
>>> 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 s you out? Is the other server > 4.4.0?
>> http://uk3.php.net/strtotime

>
> --
> Cheers
>
> Mike Morton
>
> ************************************************** **
> *
> * Tel: 905-465-1263
> * Email: mike@webtraxx.com
> *
> ************************************************** **
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
  Réponse avec citation
Vieux 31/01/2008, 21h29   #4
Mike Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

Good point

Except that generally, when am told "next Saturday" - I take that to mean
"the next Saturday" - just one more ambiguity in the english language that
makes it so hard to learn I suppose!

The odd thing about this whole situation it that it seems to have cropped up
just after we "upgraded" to 4.3.9 - prior to that, "next Saturday" worked
just peachy. I wish I knew which version we were running before that - but
that record was not kept.

I guess we are stuck with this, what maybe is a problem with this version,
until the Redhat RPM gets higher than 4.3.9 - since that is what our server
manager uses for updates....

I could always adjust it to be:

date("m/d/Y",strtotime("+ ".(6-date("w"))." days"));

That should always return the next Saturday of the week, and if I am correct
in my thinking, then even on the Saturday, 6-6 = 0 - which would return that
day... Which does, at least for my application of it, work.

I am not sure how the bug that "next" = +2 rather than +1 applys here, maybe
it is just not understanding how exactly the "next whatever" syntax is
applied....


On 1/31/08 12:57 PM, "Richard Lynch" <ceo@l-i-e.com> wrote:

> Maybe it's just me, but I've never quite figured out what people mean
> when they say "next Saturday"...
>
> Do they mean the next one coming up?
>
> Or do they mean that there's "this Saturday" coming up and "next
> Saturday" the one after that?
>
> And if I can't figure it out, why would you expect PHP to figure it out?
>
> :-)
>
> On Thu, January 31, 2008 10:27 am, Mike Morton 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@gmail.com> wrote:
>>
>>> On 31/01/2008, Mike Morton <mike@webtraxx.com> 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@webtraxx.com
>>>> *
>>>> ************************************************** **
>>>>
>>>> --
>>>> 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 s you out? Is the other server > 4.4.0?
>>> http://uk3.php.net/strtotime

>>
>> --
>> Cheers
>>
>> Mike Morton
>>
>> ************************************************** **
>> *
>> * Tel: 905-465-1263
>> * Email: mike@webtraxx.com
>> *
>> ************************************************** **
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

>


--
Cheers

Mike Morton

************************************************** **
*
* Tel: 905-465-1263
* Email: mike@webtraxx.com
*
************************************************** **
  Réponse avec citation
Vieux 31/01/2008, 21h52   #5
Jochem Maas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

Mike Morton schreef:
> Good point
>
> Except that generally, when am told "next Saturday" - I take that to mean
> "the next Saturday" - just one more ambiguity in the english language that
> makes it so hard to learn I suppose!
>
> The odd thing about this whole situation it that it seems to have cropped up
> just after we "upgraded" to 4.3.9 - prior to that, "next Saturday" worked
> just peachy. I wish I knew which version we were running before that - but
> that record was not kept.
>
> I guess we are stuck with this, what maybe is a problem with this version,
> until the Redhat RPM gets higher than 4.3.9 - since that is what our server
> manager uses for updates....
>
> I could always adjust it to be:
>
> date("m/d/Y",strtotime("+ ".(6-date("w"))." days"));
>
> That should always return the next Saturday of the week, and if I am correct
> in my thinking, then even on the Saturday, 6-6 = 0 - which would return that
> day... Which does, at least for my application of it, work.


so your actually saying 'find the closest saturday, in the future, from today'.
because if it was saturday, and you said to me "see you next saterday" I'd expect
to see you in 7 days time.

>

  Réponse avec citation
Vieux 31/01/2008, 22h01   #6
AlmostBob
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

Do you get the right answers with 'Monday' insterad of 'Next Monday'
Looks like php has been taken over by Aussies, fair dinkum

--
If at first you dont succeed
try try try again
If at first you do succeed
try not to look surprised

_
"Mike Morton" <mike@webtraxx.com> wrote in message
news:C3C7A803.AE6E0%mike@webtraxx.com...
> Good point
>
> Except that generally, when am told "next Saturday" - I take that to mean
> "the next Saturday" - just one more ambiguity in the english language that
> makes it so hard to learn I suppose!
>
> The odd thing about this whole situation it that it seems to have cropped

up
> just after we "upgraded" to 4.3.9 - prior to that, "next Saturday" worked
> just peachy. I wish I knew which version we were running before that -

but
> that record was not kept.
>
> I guess we are stuck with this, what maybe is a problem with this version,
> until the Redhat RPM gets higher than 4.3.9 - since that is what our

server
> manager uses for updates....
>
> I could always adjust it to be:
>
> date("m/d/Y",strtotime("+ ".(6-date("w"))." days"));
>
> That should always return the next Saturday of the week, and if I am

correct
> in my thinking, then even on the Saturday, 6-6 = 0 - which would return

that
> day... Which does, at least for my application of it, work.
>
> I am not sure how the bug that "next" = +2 rather than +1 applys here,

maybe
> it is just not understanding how exactly the "next whatever" syntax is
> applied....
>
>
> On 1/31/08 12:57 PM, "Richard Lynch" <ceo@l-i-e.com> wrote:
>
> > Maybe it's just me, but I've never quite figured out what people mean
> > when they say "next Saturday"...
> >
> > Do they mean the next one coming up?
> >
> > Or do they mean that there's "this Saturday" coming up and "next
> > Saturday" the one after that?
> >
> > And if I can't figure it out, why would you expect PHP to figure it out?
> >
> > :-)
> >
> > On Thu, January 31, 2008 10:27 am, Mike Morton 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@gmail.com> wrote:
> >>
> >>> On 31/01/2008, Mike Morton <mike@webtraxx.com> 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@webtraxx.com
> >>>> *
> >>>> ************************************************** **
> >>>>
> >>>> --
> >>>> 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 s you out? Is the other server > 4.4.0?
> >>> http://uk3.php.net/strtotime
> >>
> >> --
> >> Cheers
> >>
> >> Mike Morton
> >>
> >> ************************************************** **
> >> *
> >> * Tel: 905-465-1263
> >> * Email: mike@webtraxx.com
> >> *
> >> ************************************************** **
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>

> >

>
> --
> Cheers
>
> Mike Morton
>
> ************************************************** **
> *
> * Tel: 905-465-1263
> * Email: mike@webtraxx.com
> *
> ************************************************** **



  Réponse avec citation
Vieux 31/01/2008, 22h44   #7
Richard Lynch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Strtotime returns 02/09/2008 for "next Saturday"....

On Thu, January 31, 2008 3:29 pm, Mike Morton wrote:
> Except that generally, when am told "next Saturday" - I take that to
> mean
> "the next Saturday" - just one more ambiguity in the english language
> that
> makes it so hard to learn I suppose!


strtotime has always seemed to me like it's bordering on trying to do
"too much"...

I mean, it's practically trying to solve an NLP (Natural Language
Processing) problem, which AI researchers have spent decades and
billions trying to "solve" and they are not exactly getting the
(impossible) job done...

So I never rely on strtotime(), and use something simple like basic
arithmetic to compute days.

It takes out all the ambiguity since Saturday is always day 6 and
adding 7 always ends up on another Saturday.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,28410 seconds with 15 queries