Add 7 days to datetime (rather than just date) in php

hazed

New Member
I'm currently getting a datetime from a form that is stored in mysql like this:\[code\]2013-03-18 09:00:00\[/code\]However for the function I am building, I'm inserting an event into a calendar where each week is less than the final week, essentially the insert is replicated except that the start date has changed.So I get the post like this:\[code\]if (isset($_POST['submit'])){ echo $start = $_POST['startDT'].':00';}\[/code\]This works. So does the function for putting it in for one week only. What I'm stuck on, is replicating it across weeks.So my function looks like this:\[code\]if ($allYear = "yes"){ //Get Week in question - gives me the week number for that particular week $startW = getStartWeek($start); //It'll always be week 56 as the end week of the year $endW = 56; //while $i is less than or equal to 56, do it and add 1 to $i for($i = $startW; $i <= $endw; $i++) { $query = $mysqli->prepare("INSERT INTO `Events`(`Start`, `End`, `Group`, `Unit`, `Type`, `Room`, `Lecturer`) VALUES ('$start', '$end', '$group', '$unit', '$type', '$room', '$lecturer')"); /*Here is where I'd add code to make the datetime, for example: * $start is 2013-03-18 09:00:00 and $end is 2013-03-18 10:00:00 * I want $start in the next iteration to be 2013-03-25 09:00:00 and $end * to be 2013-03-25 10:00:00. I then want $start to be 2013-04-01 09:00:00 * on the iteration after that. And so on. */ $start += strtotime("+1 week"); $end += strtotime("+1 week"); }}\[/code\]
 
Back
Top