views:

35

answers:

1

Hello

I would like to produce a list of dates based on a user determined "start date", over a 12 week period.

If a user selects today's date, I need to know each date from today over 12 weeks.

Once I have these dates, I would need to insert them into a DB table.

I'd like to say I've made some in-roads into how to do this, I reckon PHP Mktime (http://php.net/manual/en/function.mktime.php) and a counter might be in right area, but I'm a bit stumped.

Any suggestions or links would be much appreciated, thanks.

EDIT:

Found this which I missed first time around:

http://stackoverflow.com/questions/1639036/php-get-next-13-dates-from-date

That's getting into the right area.

EDIT 2:

From the above listed post this works very well to get any number of dates from a given start date:

$start = strtotime($s_row['schedule_start_date']);
$dates=array();
for($i = 1; $i<=42; $i++)
{
    array_push($dates,date('Y-m-d', strtotime("+$i day", $start)));
}
print_r($dates);

I have changed the example above to get dates for 6 weeks (42 days). Does anyone have any clues as to how to modify this to split the 42 days into weeks?

So working with the results in the array, I would like to produce a list of weeks containing the calculated dates - Week 1 (list dates), Week 2 (list dates) etc...?

+1  A: 

In many, many, cases, strtotime() can be a lifesaver.

<?PHP
$userdate = strtotime($_REQUEST['whatever']);

$date1 = strtotime('+1 week',$userdate);
$date2 = strtotime('+10 days',$userdate);
$date3 = strtotime('+1 month',$userdate);

$dateN will be a timestamp, which you can just feed to date.

timdev