You are here: Re: Date, beginning of week « All PHP « IT news, forums, messages
Re: Date, beginning of week

Posted by J.O. Aho on 03/02/07 14:38

Brian wrote:
> Hi all
>
>
>
> I'm trying to write a script that works out the day of week, goes back to
> previous Monday, then removes a week and sets up 2 timestamps.
>
>
>
> EG, if the day was Wednesday 28 Feb 2007 then is would work out that the
> Monday was the 26, then remove 7 days to give me my start data and add 6
> days to give me my end date. So for Wednesday 28 Feb 2007 I should end up
> with Mon 19th Feb to Sun 26th Feb
>
>
>
> I have hit a problem, the way I am working it out all goes wrong at the
> beginning of the month, bacuse of this

Here is how you get the unixtime for Monday (00:00:00) and Sunday (23:59:59)

/* How many days today is from Monday */
$frommonday=date('N')-1;

/* Monday. we use (todays month) and (todays day minus days from Monday) */
$monday=mktime(0,0,0,date('m'),date('j')-$frommonday);

/* Sonday, wse use (todays month) and (todays day plus max days to Sunday
minus days from Monday)*/
$sunday=mktime(23,59,59,date('m'),date('j')+6-$frommonday);

So, do what you want with $monday and $sunday.

--

//Aho

 

Navigation:

[Reply to this 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

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