Calculate a due date via merge fields and current date?

Hi there!

I’m hoping that this is possible via Gravity Forms, as I am able to achieve this in Jotforms.

We are using GF to receive order requests from clients. When they get to the last part of the form, I’d like there to be a text section that will calculate the estimated completion date of their order. This would be based on the current days date (the date of the form being submitted), plus +3 days and then +7 days (as our turn around times are between 3 and 7 days).

Any help is much appreciated!

So you need to show a date that is ten days after the date the form was submitted, on the confirmation page after the form is submitted, or before the form is finally submitted (sort of a pre-submission confirmation before they submit)?

Hi! Just to clarify, I need to show a date WINDOW because our turn around times are between 3 and 7 days. So the solution needs to calculate two Dates - 3 days from the current date, and 7 days from the current date. For example, based on today’s date the text I’m envisioning would read something like this:

“Your order is estimated to be complete between the 21st of June and the 25th of June”

Ideally this would be shown on the last page of the form, so a pre-submission confirmation, but if this is not possible the confirmation page is fine too.

OK, got it. I put together a quick form that shows how this can work. You can download the form here:

[SITE REMOVED]

Save that to your desktop, then go to Forms > Import/Export > Import Forms on your site. Before you can use the form, you need this code to populate three fields in the form with the dates:

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() );
	$three_timestamp = ( 86400 * 3 ) + $local_timestamp;
	$seven_timestamp = ( 86400 * 7 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$three = date_i18n( 'jS \of F', $three_timestamp, true );
	$seven = date_i18n( 'jS \of F', $seven_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days'  => $three,
		'seven_days'  => $seven,
	);
	return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}

That is PHP code to go into your theme functions.php file, or a custom functionality plugin if you are using one.

Now, with that code on your site, preview the form you imported. You will see the three date fields pre-populated by the code (screenshot). If you submit, you will see on the confirmation screen the estimated delivery dates (screenshot).

The three date field strings are visible now, but you can make those fields hidden visibility if you like, and the procedure will still work.

Let me know if you have any questions.

Hi Chris I am really fascinated by the solution you proposed and I thank you for your sharing

I am looking for a similar but slightly different thing. Unfortunately I am not a great expert and I am finding it difficult to find the right solution

I would need to do the same thing you did only that I have to start from the data entered by the user in a date field.

add_filter( 'gform_field_value', 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name ) {
              $data_field = GFFormsModel::get_field($form, 7); // id=7 is my data field value
	$local_timestamp = GFCommon::get_local_timestamp( ‘$data_field’ );
	$three_timestamp = ( 86400 * 3 ) + $local_timestamp;
	$seven_timestamp = ( 86400 * 7 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$three = date_i18n( 'jS \of F', $three_timestamp, true );
	$seven = date_i18n( 'jS \of F', $seven_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days'  => $three,
		'seven_days'  => $seven,
	);
	return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}

But I have no result where am I wrong?

Did you enable dynamic population for each field (on the Advanced tab) and then give each field a dynamic population parameter name, which matches the names in the code?

todays_date
three_days
seven_days

Those parameter names can be anything you like (single word, lowercase and underscores) but they will need to match in the code and the form field.

Post some screenshots if you can so we can see what might be happening. What does ‘no result’ mean to you?

I should generate a contract with a automatic expiration date
I have to use two fields that must be entered by the user

Start_date:7 -> start date of the contract (input by user)
Months:8 -> Drop-down menu with the selection of the months of duration of the contract (field value= 12, 24, 36) (input by user)

So I should automatically calculate the expiration date based on the start date plus the contract duration

add_filter( 'gform_field_value', 'data', 10, 3 );
function all_the_dates( $value, $field, $name ) {
$data_field = GFFormsModel::get_field($form, 7); // id=7 is my data field value
$field_timestamp = GFCommon::get_local_timestamp( ‘$Start_date:7);

if (Months:8==12)
{
$value_timestamp = ( 86400 * 365 ) + $field_timestamp ;
// convert in days and sum 365 (1 year)
}
If(Months:8==24) // if the months selected are 24
{
$value_timestamp = ( 86400 * 730 ) + $field_timestamp ;
// convert in days and sum 730 (2 years)
}
If(Months:8==36)
{
$value_timestamp = ( 86400 * 1095 ) + $field_timestamp ;
// convert in days and sum 1095 (3 years)
}
Else
{
$value_timestamp = ( 86400 ) + $field_timestamp ;
// if no selection return the same date of expiration
}

$values = array(
‘expiration _date' => $value_timestamp,
);

return isset( $values[ $name ] ) ? $values[ $name ] : $value;

Unfortunately, being a beginner I am not able to set the code correctly!
Thanks a lot for your help :pray:

This snippet works great for my purpose and many thanks to the developer. How can this code be modified to exclude weekends? For example, if the calculated date result is a Saturday, continue adding days until the date of the following Monday (I want to display weekdays only)? Is this possible?

Any help is greatly appreciated!!!
Cheers

I’m also very interested in this answer - as I’m really struggling to find a solution.

Anyone have any thoughts?

Hi Mark. I know you have a couple support tickets submitted already, and Joshua is working on something for you. I won’t duplicate that work here.

Oh that’s great thank you