This Monday problem

Hi folks,

I need to be able to return the corresponding dates for Mondays - and
have tried various functions, scripts with varying degrees of success.
date('d-M-Y', strtotime('this monday'));

.... works, as does:

date('d-M-Y', strtotime('last monday'));

However, whilst this function works well most of the time, for some
reason it pukes on Monday 19th March - and always returns 18th Mar
(which is a Sunday!).

I could understand it if it crossed a leap year threshold of some sort
(eg. Feb 28th) - but 18 March???

This is with both PHP4 and PHP5.

Any clues?

Adam.
Anon [ Do, 22 März 2007 14:40 ] [ ID #1665527 ]

Re: This Monday problem

Message-ID: <bg1503p2n63lufgnaf9cpu9mr6pko0q1ob [at] 4ax.com> from Adam
contained the following:

>
>I need to be able to return the corresponding dates for Mondays - and
>have tried various functions, scripts with varying degrees of success.
>date('d-M-Y', strtotime('this monday'));
>
>... works, as does:
>
>date('d-M-Y', strtotime('last monday'));
>
>However, whilst this function works well most of the time, for some
>reason it pukes on Monday 19th March - and always returns 18th Mar
>(which is a Sunday!).

Spring forward, fall back?
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Do, 22 März 2007 14:46 ] [ ID #1665528 ]

Re: This Monday problem

Adam wrote:
> Hi folks,
>
> I need to be able to return the corresponding dates for Mondays - and
> have tried various functions, scripts with varying degrees of success.
> date('d-M-Y', strtotime('this monday'));
>
> ... works, as does:
>
> date('d-M-Y', strtotime('last monday'));
>
> However, whilst this function works well most of the time, for some
> reason it pukes on Monday 19th March - and always returns 18th Mar
> (which is a Sunday!).

Sure you haven't set the year to 2002 or 2013?

Does "date('d-M-Y', strtotime('last monday')+1);" make any difference?


> I could understand it if it crossed a leap year threshold of some sort
> (eg. Feb 28th) - but 18 March???
> This is with both PHP4 and PHP5.

What system does the php run on?
--

//Aho
Shion [ Do, 22 März 2007 14:47 ] [ ID #1665529 ]

Re: This Monday problem

On Thu, 22 Mar 2007 14:47:56 +0100, J.O. Aho wrote:

Wow! After a *long* break from this group, i'd forgotten how lightning
fast people here are ;-) Good to be back!

>> I need to be able to return the corresponding dates for Mondays - and
>> have tried various functions, scripts with varying degrees of success.
>> date('d-M-Y', strtotime('this monday'));
>>
>> ... works, as does:
>>
>> date('d-M-Y', strtotime('last monday'));
>>
>> However, whilst this function works well most of the time, for some
>> reason it pukes on Monday 19th March - and always returns 18th Mar
>> (which is a Sunday!).

>Sure you haven't set the year to 2002 or 2013?

Nope - I'm not playing with the year in any way.

>Does "date('d-M-Y', strtotime('last monday')+1);" make any difference?

Yes. The only way I could kludge it was to use:

date('d-M-Y', strtotime('last monday')+7)

- which gave the correct date (Mon 12th + 7 = Mon 19th). It was "this
monday" that was returning the wrong date.

I tried a function - getMondays($year) - as grabbed from the php.net
online manual hints and that one fails on that same Monday as well -
though it uses a mktime approach.

>> I could understand it if it crossed a leap year threshold of some sort
>> (eg. Feb 28th) - but 18 March???
>> This is with both PHP4 and PHP5.

>What system does the php run on?

Local servers on WinXP and Ubuntu - remote is on Unix. Same problem on
all three systems.

Weird!

Adam.
Anon [ Do, 22 März 2007 15:04 ] [ ID #1665531 ]

Re: This Monday problem

On Thu, 22 Mar 2007 13:46:59 +0000, Geoff Berrow wrote:

>Message-ID: <bg1503p2n63lufgnaf9cpu9mr6pko0q1ob [at] 4ax.com> from Adam
>contained the following:
>
>>
>>I need to be able to return the corresponding dates for Mondays - and
>>have tried various functions, scripts with varying degrees of success.
>>date('d-M-Y', strtotime('this monday'));
>>
>>... works, as does:
>>
>>date('d-M-Y', strtotime('last monday'));
>>
>>However, whilst this function works well most of the time, for some
>>reason it pukes on Monday 19th March - and always returns 18th Mar
>>(which is a Sunday!).
>
>Spring forward, fall back?

Errmm ... you'll have to explain that one to me <!!!> I'm from the UK
- now in NZ. Is that a US term for some sort of daylight saving thing?

I think you're onto something though - our clocks went back a short
while ago - I'll need to ask when it was (my short-term memory is
*appalling*!!). Wouldn't surprise me if it wasn't the Sunday (18th)
before that dreaded Monday (18/19th).

Adam.
Anon [ Do, 22 März 2007 15:08 ] [ ID #1665532 ]

Re: This Monday problem

"Adam" <anon [at] nowhere.com> wrote in message
news:a73503hnqjh4bno4b362cnnf8gpbo3fv3k [at] 4ax.com...
| On Thu, 22 Mar 2007 13:46:59 +0000, Geoff Berrow wrote:
|
| >Message-ID: <bg1503p2n63lufgnaf9cpu9mr6pko0q1ob [at] 4ax.com> from Adam
| >contained the following:
| >
| >>
| >>I need to be able to return the corresponding dates for Mondays - and
| >>have tried various functions, scripts with varying degrees of success.
| >>date('d-M-Y', strtotime('this monday'));
| >>
| >>... works, as does:
| >>
| >>date('d-M-Y', strtotime('last monday'));
| >>
| >>However, whilst this function works well most of the time, for some
| >>reason it pukes on Monday 19th March - and always returns 18th Mar
| >>(which is a Sunday!).
| >
| >Spring forward, fall back?
|
| Errmm ... you'll have to explain that one to me <!!!> I'm from the UK
| - now in NZ. Is that a US term for some sort of daylight saving thing?

it's a locale saying to help remember that when the time change occurs, we
know which direction to move the time...in the spring, move the time forward
one hour...in the fall, move it back one hour. hence, spring forward, fall
back.

it probably is related to this. however, i'd expect to see it be problematic
to more than just monday, 19 mar 2007. (and this year's time change was 11
mar).

btw, i never got why we continue to need/use dst. wasn't it originally an
agrarian function?
Steve [ Do, 22 März 2007 15:14 ] [ ID #1665533 ]

Re: This Monday problem

Adam wrote:
> On Thu, 22 Mar 2007 14:47:56 +0100, J.O. Aho wrote:
>
> Wow! After a *long* break from this group, i'd forgotten how lightning
> fast people here are ;-) Good to be back!
>
>>> I need to be able to return the corresponding dates for Mondays - and
>>> have tried various functions, scripts with varying degrees of success.
>>> date('d-M-Y', strtotime('this monday'));
>>>
>>> ... works, as does:
>>>
>>> date('d-M-Y', strtotime('last monday'));
>>>
>>> However, whilst this function works well most of the time, for some
>>> reason it pukes on Monday 19th March - and always returns 18th Mar
>>> (which is a Sunday!).
>
>> Sure you haven't set the year to 2002 or 2013?
>
> Nope - I'm not playing with the year in any way.
>
>> Does "date('d-M-Y', strtotime('last monday')+1);" make any difference?
>
> Yes. The only way I could kludge it was to use:
>
> date('d-M-Y', strtotime('last monday')+7)
>
> - which gave the correct date (Mon 12th + 7 = Mon 19th). It was "this
> monday" that was returning the wrong date.

You know that +7 is only 7 extra seconds and not seven days, 7 days = 604800
seconds.

It could of course be as Geoff says to do with the DST, specially now when the
DST has been moved at the USA and we have the problem of people who do not
keep their systems up to date, this seems to be a problem more common on
microsoft systems, but not only limited to those, I would suggest you add an
hour to the time you get with strtotime().

date('d-M-Y', strtotime('last monday')+3600);

http://www.php.net/manual/en/function.strtotime.php

When getting a date, it don't make any difference if you take the date that is
at midnight or quarter to twelve next midnight, the date itself will be the same.


--

//Aho
Shion [ Do, 22 März 2007 15:30 ] [ ID #1665534 ]

Re: This Monday problem

On Thu, 22 Mar 2007 09:14:21 -0500, Steve wrote:

>
>"Adam" <anon [at] nowhere.com> wrote in message
>news:a73503hnqjh4bno4b362cnnf8gpbo3fv3k [at] 4ax.com...
>| On Thu, 22 Mar 2007 13:46:59 +0000, Geoff Berrow wrote:
>|
>| >Message-ID: <bg1503p2n63lufgnaf9cpu9mr6pko0q1ob [at] 4ax.com> from Adam
>| >contained the following:
>| >
>| >>
>| >>I need to be able to return the corresponding dates for Mondays - and
>| >>have tried various functions, scripts with varying degrees of success.
>| >>date('d-M-Y', strtotime('this monday'));
>| >>
>| >>... works, as does:
>| >>
>| >>date('d-M-Y', strtotime('last monday'));
>| >>
>| >>However, whilst this function works well most of the time, for some
>| >>reason it pukes on Monday 19th March - and always returns 18th Mar
>| >>(which is a Sunday!).
>| >
>| >Spring forward, fall back?
>|
>| Errmm ... you'll have to explain that one to me <!!!> I'm from the UK
>| - now in NZ. Is that a US term for some sort of daylight saving thing?
>
>it's a locale saying to help remember that when the time change occurs, we
>know which direction to move the time...in the spring, move the time forward
>one hour...in the fall, move it back one hour. hence, spring forward, fall
>back.
>
>it probably is related to this. however, i'd expect to see it be problematic
>to more than just monday, 19 mar 2007. (and this year's time change was 11
>mar).
>
>btw, i never got why we continue to need/use dst. wasn't it originally an
>agrarian function?

I thought it was so schoolkids got an extra hour of daylight at the
end of the day - so they don't get knocked down by tired drivers.
Presumably, they're OK in dark mornings as drivers are rested and more
alert (not me - I don't do mornings!!!). But I digress ;-)

BTW - try it. Set your PC clock (or test server if you can) back to
around 18th Mar (trya few days before or after) and see what

date('d-M-Y', strtotime('this monday'));

gives you.

Adam.
Anon [ Do, 22 März 2007 15:33 ] [ ID #1665535 ]

Re: This Monday problem

Steve wrote:

> btw, i never got why we continue to need/use dst. wasn't it originally an
> agrarian function?

No, it had to do with the industrial revolution, as factories in general was
quite dark places, they wanted to maximize the usage of the free light from
the sun. In the same spirit, they think you use less power as you don't have
to keep lights lit in the evening (of course you will need to use the lights
in the morning as it's darker).

In an agrarian society time is quite important, you get up early anyway to
milk cows, no matter if it was light or dark.

--

//Aho
Shion [ Do, 22 März 2007 15:35 ] [ ID #1665536 ]

Re: This Monday problem

Message-ID: <a73503hnqjh4bno4b362cnnf8gpbo3fv3k [at] 4ax.com> from Adam
contained the following:

>>Spring forward, fall back?
>
>Errmm ... you'll have to explain that one to me <!!!> I'm from the UK
>- now in NZ. Is that a US term for some sort of daylight saving thing?

That's what I meant yes. I'm in the UK but I find that a handy
mnemonic. Sorry if it was cryptic.

Over here British summer time doesn't start till Sunday but I seem to
recall they changed it in the US. Don't know about NZ. Anyhow, it's
usually the problem when you get things like this and the answer, as
you've seen, is to offset the time a bit.

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Do, 22 März 2007 15:41 ] [ ID #1665537 ]

Re: This Monday problem

Geoff Berrow wrote:
> Message-ID: <a73503hnqjh4bno4b362cnnf8gpbo3fv3k [at] 4ax.com> from Adam
> contained the following:
>
>>> Spring forward, fall back?
>> Errmm ... you'll have to explain that one to me <!!!> I'm from the UK
>> - now in NZ. Is that a US term for some sort of daylight saving thing?
>
> That's what I meant yes. I'm in the UK but I find that a handy
> mnemonic. Sorry if it was cryptic.
>
> Over here British summer time doesn't start till Sunday but I seem to
> recall they changed it in the US. Don't know about NZ. Anyhow, it's
> usually the problem when you get things like this and the answer, as
> you've seen, is to offset the time a bit.

Or update the system, so it handles time correctly.


--

//Aho
Shion [ Do, 22 März 2007 15:43 ] [ ID #1665538 ]

Re: This Monday problem

"Adam" <anon [at] nowhere.com> wrote in message
news:eh4503d15mqkbdqg40noijlqc8kvobr2jn [at] 4ax.com...
| On Thu, 22 Mar 2007 09:14:21 -0500, Steve wrote:
|
| >
| >"Adam" <anon [at] nowhere.com> wrote in message
| >news:a73503hnqjh4bno4b362cnnf8gpbo3fv3k [at] 4ax.com...
| >| On Thu, 22 Mar 2007 13:46:59 +0000, Geoff Berrow wrote:
| >|
| >| >Message-ID: <bg1503p2n63lufgnaf9cpu9mr6pko0q1ob [at] 4ax.com> from Adam
| >| >contained the following:
| >| >
| >| >>
| >| >>I need to be able to return the corresponding dates for Mondays - and
| >| >>have tried various functions, scripts with varying degrees of
success.
| >| >>date('d-M-Y', strtotime('this monday'));
| >| >>
| >| >>... works, as does:
| >| >>
| >| >>date('d-M-Y', strtotime('last monday'));
| >| >>
| >| >>However, whilst this function works well most of the time, for some
| >| >>reason it pukes on Monday 19th March - and always returns 18th Mar
| >| >>(which is a Sunday!).
| >| >
| >| >Spring forward, fall back?
| >|
| >| Errmm ... you'll have to explain that one to me <!!!> I'm from the UK
| >| - now in NZ. Is that a US term for some sort of daylight saving thing?
| >
| >it's a locale saying to help remember that when the time change occurs,
we
| >know which direction to move the time...in the spring, move the time
forward
| >one hour...in the fall, move it back one hour. hence, spring forward,
fall
| >back.
| >
| >it probably is related to this. however, i'd expect to see it be
problematic
| >to more than just monday, 19 mar 2007. (and this year's time change was
11
| >mar).
| >
| >btw, i never got why we continue to need/use dst. wasn't it originally an
| >agrarian function?
|
| I thought it was so schoolkids got an extra hour of daylight at the
| end of the day - so they don't get knocked down by tired drivers.
| Presumably, they're OK in dark mornings as drivers are rested and more
| alert (not me - I don't do mornings!!!). But I digress ;-)

i don't do mornings either.

as for the truck driver scenario, i doubt it came into play when dsl was
enacted in the us...iirc, ben franklin thought it up...i think it may have
been a horse and buggy at that time. ;^)

it causes much confusion. i hate it. the north america does it one way and
europe does it another. who works by daylight anymore anyway? for those
small niches of occupation that do rely on daylight, why not just burden
them with creating their own work hours rather than having the world submit
itself to them. majority still rules, right?


| BTW - try it. Set your PC clock (or test server if you can) back to
| around 18th Mar (trya few days before or after) and see what
|
| date('d-M-Y', strtotime('this monday'));
|
| gives you.

i have no doubt that this is happening. i'm just suprised that it is only
happening with that one date.
Steve [ Do, 22 März 2007 15:44 ] [ ID #1665539 ]

Re: This Monday problem

"J.O. Aho" <user [at] example.net> wrote in message
news:56fi8aF280potU1 [at] mid.individual.net...
| Adam wrote:
| > On Thu, 22 Mar 2007 14:47:56 +0100, J.O. Aho wrote:
| >
| > Wow! After a *long* break from this group, i'd forgotten how lightning
| > fast people here are ;-) Good to be back!
| >
| >>> I need to be able to return the corresponding dates for Mondays - and
| >>> have tried various functions, scripts with varying degrees of success.
| >>> date('d-M-Y', strtotime('this monday'));
| >>>
| >>> ... works, as does:
| >>>
| >>> date('d-M-Y', strtotime('last monday'));
| >>>
| >>> However, whilst this function works well most of the time, for some
| >>> reason it pukes on Monday 19th March - and always returns 18th Mar
| >>> (which is a Sunday!).
| >
| >> Sure you haven't set the year to 2002 or 2013?
| >
| > Nope - I'm not playing with the year in any way.
| >
| >> Does "date('d-M-Y', strtotime('last monday')+1);" make any difference?
| >
| > Yes. The only way I could kludge it was to use:
| >
| > date('d-M-Y', strtotime('last monday')+7)
| >
| > - which gave the correct date (Mon 12th + 7 = Mon 19th). It was "this
| > monday" that was returning the wrong date.
|
| You know that +7 is only 7 extra seconds and not seven days, 7 days =
604800
| seconds.
|
| It could of course be as Geoff says to do with the DST, specially now when
the
| DST has been moved at the USA and we have the problem of people who do not
| keep their systems up to date, this seems to be a problem more common on
| microsoft systems, but not only limited to those, I would suggest you add
an
| hour to the time you get with strtotime().
|
| date('d-M-Y', strtotime('last monday')+3600);
|
| http://www.php.net/manual/en/function.strtotime.php
|
| When getting a date, it don't make any difference if you take the date
that is
| at midnight or quarter to twelve next midnight, the date itself will be
the same.

i agree. i've seen others have date calc problems here along with some good
feedback as to why they happen. each solution relied on either being
specific with the time, ensuring that it was not 00:00:00, and in this case,
even adding an hour...which should circumvent this problem as well.

good on ya.
Steve [ Do, 22 März 2007 15:46 ] [ ID #1665540 ]
PHP » alt.php » This Monday problem

Vorheriges Thema: PHP files in Apache load as text?
Nächstes Thema: Submitting Post Information Through fopen()