How to perform Gravity Forms time calculations in GravityView using GravityMath
This guide walks you through adding a duration field in Gravity Forms, displaying entries with GravityView, and calculating averages, fastest, and slowest times using the GravityMath plugin.
Watch a video walkthrough
Here are the steps. Let's get started!
1. Add a field called Duration in Gravity Forms
- Edit your form in Gravity Forms.
- Add a Single Line Text field.
Expand the field settings.
Check Enable Input Mask.
From the Mask Type dropdown, select either:
- Minutes duration
Hours duration
For this example, select Minutes.
- Rename the field to Duration.
- Save the form.
2. Create a View in GravityView
- Create a new View based on your form.
- Name the View (example: Duration Times).
- Add the Duration field to the View layout.
- In the field settings, check Add field calculations to the table footer (added by GravityMath).
- Leave the default calculation settings for now.
- Publish the View.
3. Add Entries to Test
- Preview your form.
- Submit several entries with different durations, for example:
- 10 minutes
- 15 minutes
- 30 seconds
- 15 minutes 30 seconds
- Return to the View to see the results.
- You should see the list of durations entered.
- By default, the Total of all entries is displayed.
4. Customize the Calculations
- Edit the View settings.
- Instead of showing the Total, configure the field to display the Average.
- Add a custom label, for example:
Average speed: {result}
- Set the formatting option to display numeric values instead of words.
- Save the View.
When you refresh the View, you’ll see the label and result, e.g.:
Average speed: 10 minutes and 15 seconds
Summary
- Gravity Forms: Collects duration entries.
- GravityView: Displays and organizes the entries.
- GravityMath: Adds calculations like totals, averages, fastest, and slowest times.
This workflow makes it simple to track time durations and analyze them directly within WordPress.
Video Transcript:
We're going to be adding a duration field to Gravity Forms and then calculating averages and fastest and slowest times using GravityView and GravityMath plugin to get started, I'm going to add a single line, text, field, click to expand it, check the input mask button.
And this is key for the GravityMath plugin: selecting the mask type to be either minutes or hours duration.
I'm going to select minutes for this example. I'm going to name the field duration. I'm going to save the form and then display the form entries.
I'm going to create a View based on this, and I'll call it "Duration Times". I'm feeling creative today, apparently! Now, in order to display the field, I'm going to add it to the View and I'm going to select the field options and going to check the add field calculations to the table footer setting.
This is added by GravityMath. So when I check that, you'll see, that I have the option to format the results in the way that I want.
And I'm going to leave this default value for now and we'll come back here. I'm going to publish the View and now all we need is some entries.
I'm going to click, to preview the form, and let's add a few entries, in 10 minutes. Let's add 15 minutes.
Let's add how about 30 seconds? So 10 minutes, 15 minutes, 30 seconds. And let's do 15 minutes and 30 seconds.
All right. Let's take a look again at the View. Okay. I'm going to uncheck approved entries only, so I don't need to improve the entries and let's take a look at the website.
Let's see what it looks like. So you can see the duration times here that we just entered. And the total of those times is here.
As we expected. Now, I'm going to change the field settings to not show the total, but let's instead show the average speed.
And instead of just showing the value, let's also say, let's set a label that's different than what the default is, which is just the value.
Let's set a label that says "Average speed: {result}". And instead of showing the numbers in English, let's show them as values, just pure numbers.
Let's see how that goes. I'm going to save the View, go back over, refresh the screen, and we can see "Average speed:".
That's the label that we set up: 10 minutes and 15 seconds.