Jump to content

Recommended Posts

Hi

 

 

I am trying to increment the date using weekly increments.

I need to determine the start and end dates and the week number of the year.

 

If you can suggest another approache that is OK,  but this is what I came up with.

 

I am having problems getting the correct increment and week number of the year.

 

result received:

(week number) 01-1

(next start) 1970-01-07

(next end) 1970-01-07

 

result expected:

(week number) 02

(next start) 2008-02-14

(next end) 2008-02-21

 

<?
$week number = 1;//the for loop increment number 
$week cycle = 2;//This will provide the date for the 1st, 2nd, 3rd or 4th week of the month.
$start_date = "2008-02-01";


$nw = ($week number * $week cycle) + 1;//+ 1 to be in the next range	

$next_start = date("Y-m-d",strtotime("+$nw week", $start_date));
$next_end = date('Y-m-d',strtotime("+1 week", $next_start))."<br>";
$week_number = date('W', $next_start);//week number of the year
?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/86694-increment-date-by-week/
Share on other sites

Two different ways to use strtottime() with something like "+7 days"

 

1 ) with a string date

 

$start_date = "2008-02-01";

echo date ('d/m/y' , strtotime ("+7 days $start_date"));         // single arg

 

2 ) with a time value

 

$start_date = strtotime ("2008-02-01)";

echo date ('d/m/y' , strtotime ("+7 days", $start_date));         // two args

 

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.