# Agreement Expiration Date \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899>\
**Category:** Get Help\
**Tags:** gform\_field\_value, date-field\
**Created:** [February 13, 2022, 4:37am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899 "2022-02-13T04:37:44Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5b2716ffd834a4.6](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b2716ffd834a4.6/32/4602_2.png) [@user5b2716ffd834a4.6](https://community.gravityforms.com/u/user5b2716ffd834a4.6)\
**Post date:** [February 13, 2022, 4:37am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/1 "2022-02-13T04:37:44Z")

</div>

Hi GF Support Team.

I need help implementing an expiration date of a contract based on the date the agreement is signed.

I tweaked this code based on this [post](https://community.gravityforms.com/t/calculate-a-due-date-via-merge-fields-and-current-date/5167/4) but it returned an invalid code.

Our goal is to have the expiration date auto-populated 6 months after the signed date (today’s date) and the output is ex: “21st of June 2022”.

```auto
add_filter( 'gform_field_value', 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name, ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration = date_i18n( 'jS \of F', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days' => $three,
		'182_days' => $expiration,
	);
	return isset( $values[$name] ) ? $values[$name] : $value;
}

```

Any help would be greatly appreciated.

Thank you!

Liza

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [February 14, 2022, 3:56am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/2 "2022-02-14T03:56:56Z")

</div>

Hi Liza. What is the invalid code that was returned? Was the date wrong, or in the wrong format, or did you have an error message?

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [February 14, 2022, 4:02am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/3 "2022-02-14T04:02:30Z")

</div>

Looking quickly at the code, there are at least a couple of problems with the code:

```auto
add_filter( 'gform_field_value', 'all_the_dates', 10, 3 );

```

In the first line, `gform_field_value` should be something like `gform_field_value_parametername` where `parametername` is the name you gave to the field in your form which is set up to be populated dynamically. It could be:

```auto
expiration
sixmonths
date
mojo

```

Whatever you use in the field parameter name is the same word you need to use in this filter:

```auto
add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );
add_filter( 'gform_field_value_sixmonths', 'all_the_dates', 10, 3 );
add_filter( 'gform_field_value_date', 'all_the_dates', 10, 3 );
add_filter( 'gform_field_value_mojo', 'all_the_dates', 10, 3 );

```

In this line:

```auto
function all_the_dates( $value, $field, $name, ) {

```

The comma after `$name` does not need to be there. I’m not sure if that is causing a problem or not.

If you share the actual error message you are receiving after updating the code, that will help us figure it out. Thank you.

---

<div class="post-metadata">

**Author:** ![user5b2716ffd834a4.6](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b2716ffd834a4.6/32/4602_2.png) [@user5b2716ffd834a4.6](https://community.gravityforms.com/u/user5b2716ffd834a4.6)\
**Post date:** [February 14, 2022, 5:23am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/4 "2022-02-14T05:23:39Z")

</div>

Hi Chris.

Thank you for your reply! To answer your first question, it just say invalid code and the site went down 🙂  
OK let me apply your corrections and will get back to you whatever the outcome is.

Thanks Chris!  
Cheers,  
Liza

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [February 14, 2022, 5:48am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/5 "2022-02-14T05:48:59Z")

</div>

Hi Liza. That means there is a fatal error which will be logged somewhere, normally the web server error log. WordPress also sends an email to the website administrator. We’ll need the actual error message from one of those two locations to help troubleshoot. Thank you.

---

<div class="post-metadata">

**Author:** ![user5b2716ffd834a4.6](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b2716ffd834a4.6/32/4602_2.png) [@user5b2716ffd834a4.6](https://community.gravityforms.com/u/user5b2716ffd834a4.6)\
**Post date:** [February 15, 2022, 1:59am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/6 "2022-02-15T01:59:58Z")

</div>

Hi Chris.

I added this code:

```auto
add_filter( 'gform_field_value_expiration’, 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration = date_i18n( 'jS \of F', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days' => $three,
		'182_days' => $expiration,
	);
	return isset( $values[$name] ) ? $values[$name] : $value;
}

```

This is the error:  
2022-02-15T01:52:34+00:00 CRITICAL syntax error, unexpected ‘all\_the\_dates’ (T\_STRING), expecting ‘)’ in /var/www/vhosts/lifeskills4kids.com.au/staging.lifeskills4kids.com.au/wp-content/themes/impressense-web-studios/functions.php on line 305

Thanks,  
Liza

---

<div class="post-metadata">

**Author:** ![tugmariner](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tugmariner/32/4465_2.png) [@tugmariner](https://community.gravityforms.com/u/tugmariner)\
**Post date:** [February 15, 2022, 5:48am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/7 "2022-02-15T05:48:32Z")

</div>

> [@user5b2716ffd834a4.6](#):
>
> `add_filter( 'gform_field_value_expiration’, 'all_the_dates', 10, 3 );`

Possibly a different error than you had the first time. The single quote at the end of gform\_field\_value\_expiration is different than the one preceding and the two wrapping all\_the\_dates.

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [February 15, 2022, 2:54pm UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/8 "2022-02-15T14:54:04Z")

</div>

> [@user5b2716ffd834a4.6](#):
>
> ```auto
> add_filter( 'gform_field_value_expiration’, 'all_the_dates', 10, 3 );
> 
> ```

Fixing that fancy quote to make it a single quote got rid of the error for me.

---

<div class="post-metadata">

**Author:** ![user5b2716ffd834a4.6](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b2716ffd834a4.6/32/4602_2.png) [@user5b2716ffd834a4.6](https://community.gravityforms.com/u/user5b2716ffd834a4.6)\
**Post date:** [February 15, 2022, 3:00pm UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/9 "2022-02-15T15:00:55Z")

</div>

Aha, yes, I think that was causes the invalid code. Fixed that already. Didn’t return an error but it did not turn out the expected outcome.

```auto
add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );

```

The expiration date is still not auto-populated.

 ![Screen Shot 2022-02-15 at 10.47.30 PM](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/3/373bfbdf26fee8beac235047e275ffc1baa5ef4d.png)

Code in the functions.php

```auto
add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration = date_i18n( 'jS \of F', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days' => $three,
		'182_days' => $expiration,
	);
	return isset( $values[$name] ) ? $values[$name] : $value;
}

```

I’m not sure what needs to be added/changed to get this result (ex): **22/07/2022**

Thank you all!

---

<div class="post-metadata">

**Author:** ![tugmariner](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tugmariner/32/4465_2.png) [@tugmariner](https://community.gravityforms.com/u/tugmariner)\
**Post date:** [February 15, 2022, 5:52pm UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/10 "2022-02-15T17:52:28Z")

</div>

```auto
$expiration = date('jS \of F Y', strtotime($local_timestamp. ' + 6 months'));
$standard = date('d/m/Y', strtotime($local_timestamp. ' + 6 months'));

```

Results:  
15th of August 2022  
15/08/2022

---

<div class="post-metadata">

**Author:** ![tugmariner](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tugmariner/32/4465_2.png) [@tugmariner](https://community.gravityforms.com/u/tugmariner)\
**Post date:** [February 15, 2022, 6:59pm UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/11 "2022-02-15T18:59:18Z")

</div>

Looking at the tree and missed the forest 😀

```auto
add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration_short = date_i18n( 'd/m/Y', $expiration_timestamp, true );
	$expiration_long = date_i18n( 'jS \of F Y', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'expiration' => $expiration_long,
	);
	return isset( $values[$name] ) ? $values[$name] : $value;
}

```

The expiration\_long variable returns: **16th of August 2022**.  
The expiration\_short variable returns: **16/08/2022**.

Update ‘expiration’ =\> to whichever one you want displayed.

Don’t forget to set the field for dynamic population and use ‘expiration’ as the parameter.

---

<div class="post-metadata">

**Author:** ![user5b2716ffd834a4.6](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b2716ffd834a4.6/32/4602_2.png) [@user5b2716ffd834a4.6](https://community.gravityforms.com/u/user5b2716ffd834a4.6)\
**Post date:** [February 16, 2022, 12:52am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/12 "2022-02-16T00:52:21Z")

</div>

YAY, it worked! I used the short date. Thank you @tugmariner 🙂 😊

 ![Screen Shot 2022-02-16 at 8.51.03 AM](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/c/c3aae815e47985bae7539e11a1c33280dfa20ea5.png)

Thanks also @chrishajer 🙂

Cheers guys!

Liza

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [February 16, 2022, 1:00am UTC](https://community.gravityforms.com/t/agreement-expiration-date-resolved/11899/13 "2022-02-16T01:00:35Z")

</div>


