I'm running a cron job to change task dates to the current week. Currently I am changing the date by taking the date and moving it on by 1 week.
Current Controller code:
function weekly_tasks()
{
$this->load->model('tasksmodel');
$data['weekly_tasks'] = $this->tasksmodel->get_weekly_tasks();
var_dump($data);
foreach ($data['weekly_tasks'] as $row)
{
// change parent task date to next week
$date = $row->due_date;
$newdate = strtotime ( '+1 week' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );
$row->due_date = $newdate;
// set up task update var
$task_update = $row;
$task_id = $row->task_id;
//create this week's task
$task_create = $row;
$this->tasksmodel->create_weekly_tasks($task_create);
var_dump($task_create);
// update the task to next week
$this->tasksmodel->update_weekly_tasks($task_update, $task_id);
var_dump($task_update);
}
}
The above code takes a date last week 2015/10/14 and changes the date to the same weekday this week 2015/10/21.
Now I need to take any date in the past and change it to the same day of the current week as in the original date. So 2015/09/09 should change to the same day this week 2015/10/21.
Do I still use intervals by getting the difference in interval between old date and today or is there a better way to do it?