Subtract X Hours to user's chosen time and display it in a HTML field

Hi there :slight_smile:

I have a short question: is it possible to do a Math Calculation that subtract X Hours to a user’s chosen time?

Scenario: I have a form with 3 steps (page break)

Page 1: user chooses 13:35 in a time filed
Page 2: show text
Page 3: in a HTML filed display chosen time - (minus) 3 Hours → 10:35

So basically subtract 3 Hours to chosen time
How can I achieve that?

Many many thanks in advance!

Hi Antonio. I think I replied to your support ticket already, but my recommendation would be to use this plugin from Gravity Wiz:

Hi @chrishajer, yes I saw and thanks!

I did not got it: the plugin only calculates the difference between 2 times right?

What I would need it’s actually something more “simple”: subtract -3 hours to a given time and display the result into an HTML field.

You think this is doable with that plugin?

Hi Antonio. I recommend asking Gravity Wiz. I’m not sure. I realize your needs are simpler than what that plugin offers. It handles all the heavy lifting for the date/time though, so I think it should be possible.

Hi Antonio,

You can use our Populate Date snippet to populate another Time field with the modified time and then use the Live Merge tag feature of GP Populate Anything to display the new Time in an HTML field. For the Populate Date snippet, the configuration will be like so;

# Configuration

new GW_Populate_Date( array(
    'form_id'         => 123,
    'source_field_id' => 4, 
    'target_field_id' => 5,
    'modifier'        => '-3 hours',
) );

I hope this helps. If you have any questions and have an active Gravity Perks License. you can get in touch with us via our support form.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.