Adding one year to date conversion from dmy format to timestamp in Gravity Forms

I have a WordPress site using Gravity Forms where I need to convert dates from day-month-year format to Unix timestamps. The basic conversion works perfectly when I add this code to my functions.php file. However, I’m struggling to add an extra year to one of the converted dates.

function convert_form_dates($form_data){
    // Getting date values from form fields 501 and 502
    $start_date = $_POST['input_501'];
    $end_date = $_POST['input_502'];
    
    // Converting to timestamps
    $converted_start = strtotime($start_date);
    $converted_end = strtotime($end_date);
    
    // Saving converted values to hidden fields 503 and 504
    $_POST['input_503'] = $converted_start;
    $_POST['input_504'] = $converted_end;
}

add_action('gform_pre_submission', 'convert_form_dates');

When I try to modify the line $converted_start = strtotime($start_date); to $converted_start = strtotime('+ 1 year', $start_date); I get January 1st, 1971 instead of the original date from field 501 plus one year. What am I doing wrong with the syntax?

You’re passing parameters to strtotime() wrong. Don’t concatenate the timestamp in the first parameter – put it as the second one instead. Try this: $converted_start = strtotime('+ 1 year', strtotime($start_date)); This converts your date string to a timestamp first, then adds a year to it. That January 1st, 1971 result means strtotime() is failing and returning false, which becomes timestamp 0 (Unix epoch). I’ve hit this exact issue before with PHP date stuff. You could also use DateTime objects for cleaner code: $date = DateTime::createFromFormat('d-m-Y', $start_date); $date->add(new DateInterval('P1Y')); $converted_start = $date->getTimestamp(); This gives you better control over date format parsing.

The issue is you need the base timestamp as the second parameter in strtotime, not mixed with the date string. Try this:

$converted_start = strtotime('+1 year', strtotime($start_date));

Honestly though, PHP date functions get messy quick. I’ve dealt with this same headache way too many times.

I ended up automating my entire form processing instead. Rather than writing custom PHP that breaks with WordPress updates or edge cases, I built a workflow that catches Gravity Forms submissions automatically.

It handles date conversions, adds/subtracts time periods, and validates date ranges before processing. No more debugging strtotime weirdness or format parsing failures.

Set it up once and it’s handled thousands of submissions without touching code. Much cleaner than maintaining custom functions.php hacks.

Check out the form automation here: https://latenode.com