Reply to Re: This Monday problem

Your name:

Reply:


Posted by J.O. Aho on 03/22/07 14:30

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация