Reputation: 5553
I am having trouble adjusting a week range in PHP.
I have it working to show the current work week starting on monday.
So for this week it shows 11/29/2010 - 12/03/2010.
I need to modify this to start from the current work week's monday and show and end date of two fridays from the monday.
So for example currently it would show a start date of 11/29/2010 and and end date of 12/10/2010.
Here is my code
<?
$timestamp = time();
echo date("m/d/Y", strtotime("this monday", $timestamp));
echo " - ";
echo date("m/d/Y", strtotime("Next Friday", $timestamp));
?>
How do I add +7 to "Next Friday"
thx
Upvotes: 0
Views: 697
Reputation: 116
Just realised that "previous monday" only works the current day is tuesday or later...but it's a starting point for you..
<?php
$monday = date('m/d/Y', strtotime("previous monday"));
$friday = date('m/d/Y', strtotime($monday . " + 11 days"));
echo $monday . ' - ' . $friday ;
?>
Upvotes: 1
Reputation: 47321
You cannot use this monday
to construct date time,
as it went pass Monday, it return next Monday
here is my suggestion
<?
$current_wkday = date('N', time());
switch ($current_wkday)
{
/* assuming on sunday, get next monday */
case 0: $this_monday = strtotime('+1 day'); break;
case 1: $this_monday = time(); break;
default: $this_monday = strtotime('-'.($current_wkday-1).'day'); break;
}
echo date("m/d/Y", $this_monday); /* 11days = 7+(5-1) */
echo " - ";
echo date("m/d/Y", $this_monday+(86400*11));
?>
Upvotes: 1
Reputation: 27827
Instead of strtotime("Next Friday", $timestamp)
do strtotime("Next Friday", $timestamp) + 60*60*24*7
(add the number of seconds in a week).
Upvotes: 1