Regina Schlauklug: PHP +7 day

Beitrag lesen

Sowas einfaches?

<?php
$daysToAdd   = 7;
$monthsToAdd = 0;
$yearsToAdd  = 0;
list($Y, $m, $d) = explode('-', '2016-03-27');
echo date( 'Y-m-d', mktime(0,0,0, $m+$monthsToAdd, $d+$daysToAdd, $Y+$yearsToAdd) );
echo "\n";
2016-04-03

Rückwärts:

<?php
$daysToAdd   = -7;
$monthsToAdd = 0;
$yearsToAdd  = 0;
list($Y, $m, $d) = explode('-', '2016-04-03');
echo date( 'Y-m-d', mktime(0,0,0, $m+$monthsToAdd, $d+$daysToAdd, $Y+$yearsToAdd) );
echo "\n";
2016-03-27