Add 365 days to created by field

I am creating a certificate for users using GravityPDF and want to have a start date and expiration date. I can get the start date by using {Date:11} which is the created by field, but I can’t figure out how to create the expiration date. It should be {Date:11} + 365 if that makes sense.

Any help would be great. Thanks!

Hi Mareider,

This should be possible with our Populate Dates snippet. The snippet allows you to populate a Date field with a modified version of a date. We actually have detailed documentation on how the snippet works and how to use it. Please check it out and let me know if you have any questions.

Best,

1 Like

Surely there has to be a quicker way than 2000 lines of code right?

Hi @mareider. If you need the date 365 days in advance only for the expiration date on the PDF, you could use the gform_pre_submission filter to add 365 days to your date, store that in a field in the form, then use the merge tag for that field in the PDF.

Example 3 here shows manipulating some dates with PHP functions (in this case, to figure the age from the submitted date and current date) but you can do something similar using PHP date functions:

I tried using Example 3 and just changing my IDs. The date field ID is 11 and I added a new Expiration Date hidden field that has an ID of 100, but nothing is showing up.

add_action( 'gform_pre_submission_1', function ( $form ) {
// Get the date field.
$date_field_id = '11';
$date_field    = GFAPI::get_field( $form, $date_field_id );

// Get the date field value.
$value      = $date_field->get_value_submission( array() );
$date_value = GFFormsModel::prepare_date( $date_field->dateFormat, $value );

// Get the DateTime object representing the difference between the date field value and today.
$today = new DateTime();
$diff  = $today->diff( new DateTime( $date_value ) );

// Populate field 11 with the age.
$_POST['input_100'] = $diff->y;

} );

That is the code in my functions.php file and in the php file that generates the PDF I used {Expiration Date:100} to try and populate the value.