Amit Dhamu

Software Engineer

Add Month or Year to Date

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

 date / strtotime / date range / php

OnClick FunctionElement Is Not

Show Comments

Made with by Amit Dhamu.
© MMXX. All rights reserved.