'Gravity Form - expiration date with year
I need help with this code. This code's output is example "21st of June". I would like to add year on that. How can I insert that in the code as I got an invalid code when I added the 'Y':)
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;
}
Appreciate any input as soon as anyone can :) Thank you!!!
Cheers, Liza
Solution 1:[1]
I think your error is coming from the fact that $three is undefined: 'three_days' => $three, Remove that line and see if your site still receives an error.
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 Y', $local_timestamp, true );
$expiration = date_i18n( 'jS \of F Y', $expiration_timestamp, true );
$values = array(
'todays_date' => $today,
'182_days' => $expiration,
);
return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rochelle |
