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

Posted by Rik on 03/02/07 14:35

Brian <brian_no_spam@nrwp.co.uk> wrote:
> 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.

Does it go back to the previous Monday if the current day is a Monday?

> EG, if the day was Wednesday 28 Feb 2007 then is would work out that t=
he
> 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

<?php
$date =3D ; //some timestamp

//strftime('%w') gives day of the week 0-6
$day =3D intval(strftime('%w',$date));

//change to < if the same monday is OK)
$day_diff =3D (($day =3D=3D 0) ? 6 : $day - 1)*(60*60*24);

$start =3D $date - (60*60*24*7) - $day_diff;
$end =3D $start + (60*60*24*6);
?>
-- =

Rik Wasmus

 

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

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