Reputation: 22820
today 22-05-2011 so it should be 29-05-2011? ( plus 1 week )
or
today 22-05-2011 so it should be 15-05-2011? ( minus 1 week )
thanks for looking in.
Adam Ramadhan
Upvotes: 36
Views: 84734
Reputation: 417
In case If you dint want to hard code today's date you can use Carbon class methods of php.
Carbon::now()->subWeek(1);
Carbon::now()->addWeek(1);
Upvotes: 0
Reputation: 13435
strtotime will handle this.
$pDate = strtotime('22-05-2011 + 1 week');
echo date('d-m-Y',$pDate);
Added: This is if you want to start from a specific date. If you just want 'today' +/- a week', mark JohnP's answer as correct. : )
Upvotes: 17
Reputation: 41306
You can use the DateTime
class to do calendar calculations. For exaple, to add one week, you could use code like this:
$date = new DateTime('22-05-2011');
$date->modify('+1 week');
Upvotes: 32
Reputation: 50039
Use strtotime()
echo date('d-m-Y', strtotime("+1 week")); //1 week in the future
echo date('d-m-Y', strtotime("-1 week")); //1 week ago
Upvotes: 75