Reputation: 59
I created a script that creates a time period based on the users input. For this example we'll use a weekly time frame period. The user visits my site and would like to receive leads on a weekly basis, starting from a set date in which they enter and every 7 days the leads will be sent to the user. What I need to output is how many leads were sent out for the month instead of the day of the week generated from the script. Basically combining the weekly days by then differentiating which day is in January, February, and etc..
<input type='hidden' name='start_date' value='12/27/2012'>
$date1 = $_POST['start_date'];
$date2 = date('M j, Y', strtotime($date1 . ' + 7 Day')); // echo Jan 3, 2013 sent 5 leads
$date3 = date('M j, Y', strtotime($date2 . ' + 7 Day')); // echo Jan 10, 2013 sent 3 leads
$date4 = date('M j, Y', strtotime($date3 . ' + 7 Day')); // echo Jan 17, 2013 sent 7 leads
$date5 = date('M j, Y', strtotime($date4 . ' + 7 Day')); // echo Jan 24, 2013 sent 9 leads
$date6 = date('M j, Y', strtotime($date5 . ' + 7 Day')); // echo Jan 31, 2013 sent 8 leads
$date7 = date('M j, Y', strtotime($date6 . ' + 7 Day')); // echo Feb 7, 2013 sent 1 leads
$date8 = date('M j, Y', strtotime($date7 . ' + 7 Day')); // echo Feb 14, 2013 sent 8 leads
$date9 = date('M j, Y', strtotime($date8 . ' + 7 Day'));
$date10 = date('M j, Y', strtotime($date9 . ' + 7 Day'));
$date11 = date('M j, Y', strtotime($date10 . ' + 7 Day'));
$date12 = date('M j, Y', strtotime($date11 . ' + 7 Day'));
$date13 = date('M j, Y', strtotime($date12 . ' + 7 Day'));
$date14 = date('M j, Y', strtotime($date13 . ' + 7 Day'));
$date15 = date('M j, Y', strtotime($date14 . ' + 7 Day'));
$date16 = date('M j, Y', strtotime($date15 . ' + 7 Day'));
I want to output Jan 32 Leads & Feb 9 Leads. I cannot simply add the variables because it's based on the start date in which are different. Please any assistance would be much appreciated.
Upvotes: 0
Views: 341
Reputation: 3713
If I were you I would use DatePeriod as it is perfectly what you want :
$start = DateTime::createFromFormat('M j, Y',$_POST['start_date']);
$interval = new DateInterval('P1D');
$period = new DatePeriod($start,$interval,16);//as you want 16 iteration
foreach($period as $iteration=>$date){
//use $iteration to know which one you are processing
echo $date->format('M j, Y');
}
Upvotes: 0