d
Amit DhamuSoftware Engineer
 

Add Month or Year to Date

1 minute read 00000 views
function DateRange($from, $date_format, $range) {
    return date($date_format, strtotime(date($date_format, strtotime($from)) . $range));
}

$df = 'd-m-Y';
$date = date($df); // today
$how_far_ahead = '+2 years';

$new_date = DateRange($date, $df, $how_far_ahead);
echo $new_date; // will echo date 2 years ahead in d-m-Y format