Jump to content

get start and end date of the following week


jarvis

Recommended Posts

Hi,

 

I'm trying to alter the code below. It cuurently finds the start and end date of this week, no matter what day you're on.

 

What I now need is to find the start & end date of next week, again, no matter what day you're on of this week

 

Thanks to aleX_hill for the following code:

<?php
#THIS WEEK
$dayOfWeek = date("w"); #The number of the day of the week. Sun = 0, Sat = 1
$todayDayOfMonth = date("d"); #The day of the month
$thisMonth = date("m"); #The number of this month. Jan = 1, Dec = 12

$firstDayOfWeek = $todayDayOfMonth - $dayOfWeek; #The day of the month for the beginning of the week (Sun)
if($firstDayOfWeek < 1) #The beginning of the week was in the previous month
{
$monthBeginWeek = $thisMonth - 1;
$firstDayOfWeek = $firstDayOfWeek + date("t",mktime(0,0,0,$monthBeginWeek,1,date("Y")));
} else {
$monthBeginWeek = $thisMonth;
}
$lastDayOfWeek = $todayDayOfMonth + (6 - $dayOfWeek); #Get the day of the month of the end of the week (sat)
if($lastDayOfWeek > date("t")) #if the day of the month is larger then the number of days in the month
{
$monthEndWeek = $thisMonth + 1;
$lastDayOfWeek = $lastDayOfWeek - date("t"); #Then take the number of days in the week to get the day number of the next week
} else {
$monthEndWeek = $thisMonth;
}
$start_of_week = date("Y-m-d",mktime(0,0,0,$monthBeginWeek,$firstDayOfWeek,date("Y")));
#echo $start_of_week;
$end_of_week = date("Y-m-d",mktime(0,0,0,$monthEndWeek,$lastDayOfWeek,date("Y")));
#echo $end_of_week;
?>

 

 

Any help is much appreciated!

 

TIA

Modifying your code...

 

<?php
#THIS WEEK

# ONE WEEK FROM TODAY
$ts2 = time() + 60*60*24*7;



$dayOfWeek = date("w", $ts2); #The number of the day of the week. Sun = 0, Sat = 1
$todayDayOfMonth = date("d", $ts2); #The day of the month
$thisMonth = date("m", $ts2); #The number of this month. Jan = 1, Dec = 12

$firstDayOfWeek = $todayDayOfMonth - $dayOfWeek; #The day of the month for the beginning of the week (Sun)
if($firstDayOfWeek < 1) #The beginning of the week was in the previous month
{

$monthBeginWeek = $thisMonth - 1;

$firstDayOfWeek = $firstDayOfWeek + date("t",mktime(0,0,0,$monthBeginWeek,1,date("Y",$ts2)));
} else {

$monthBeginWeek = $thisMonth;
}
$lastDayOfWeek = $todayDayOfMonth + (6 - $dayOfWeek); #Get the day of the month of the end of the week (sat)
if($lastDayOfWeek > date("t", $ts2)) #if the day of the month is larger then the number of days in the month
{

$monthEndWeek = $thisMonth + 1;

$lastDayOfWeek = $lastDayOfWeek - date("t", $ts2); #Then take the number of days in the week to get the day number of the next week
} else {

$monthEndWeek = $thisMonth;
}
$start_of_week = date("Y-m-d",mktime(0,0,0,$monthBeginWeek,$firstDayOfWeek,date("Y", $ts2)));
echo $start_of_week  . "<br>";
$end_of_week = date("Y-m-d",mktime(0,0,0,$monthEndWeek,$lastDayOfWeek,date("Y", $ts2)));
echo $end_of_week;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.