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
[Back to original message]
|