Calculating start and end dates.

I am very new to PHP. I have been learning over the last two weeks and I am finding it very challenging. My strengths are in CSS/HTML and this is my first look at an “Object-Oriented Language”

My question is how exactly do I print out the first and last days of the current week? Given that today is Wednesday, September 15, 2010,

I need a print statement to say something like:
This week began on Sun, 12/10 and will end on Sat, 18/10.

Next week this statement will print:
This week began on Sun, 19/10 and will end on Sat, 25/10.

I REALLY appreciate any help you can provide. I have been staring at this for hours upon hours for the last week and I am still at square one. Thank you again.

  • Andrew

Here is the code that will display week’s first date and week’s last date by given date:


$day = strtotime(‘September 15, 2010’);

$week_first_day = $day - (date(‘w’,$day) % 7) * 86400;
$week_last_day = $week_first_day + 6 * 86400;

echo ‘This week began on ‘.date(‘D, j/n’,$week_first_day).’ and will end on ‘.date(‘D, j/n’,$week_last_day).’.’;


Sponsor our Newsletter | Privacy Policy | Terms of Service