---
title: "Sum GravityMath values for today, a custom date range, or a rolling window"
date: 2026-04-23
author: "GravityKit"
link: "https://www.gravitykit.com/docs/gravitymath/how-to-sum-gravitymath-values-for-today-or-a-date-range/"
---

Use this pattern when you need the sum of a field's values over a specific time period — for example, "total revenue entered today" or "total hours logged between 2026-04-15 and 2026-04-20." The `[gravitymath]` shortcode's `filter` parameter only accepts one condition per field, so you can't express "between two dates" directly. Instead, you nest two shortcodes and subtract.

## Before you start

- You need GravityMath installed and activated.
- You should be comfortable with the `[gravitymath]` shortcode and its `filter` parameter. If you aren't, start with [The  Shortcode](https://www.gravitykit.com/docs/gravitymath/math-shortcode/) and [Math filters: How to target a specific field value](https://www.gravitykit.com/docs/gravitymath/how-to-target-a-specific-field-value-with-gvmath-filters/).
- You should be using `scope="form"` or `scope="view"` — the `filter` parameter only works with those two scopes.

## Why you need two shortcodes

The `filter` parameter can only hold one condition per field. You cannot write `filter_date_created=2026-04-15&filter_date_created=2026-04-20` and have GravityMath interpret that as a range — the second condition overwrites the first.

The workaround is to compute two running totals and subtract them:

- The sum of all entries created **before the end boundary**.
- The sum of all entries created **before the start boundary**.

Subtracting (1) minus (2) leaves only the entries inside the range.

Both sums use `op_date_created=lt` ("less than"), which excludes the boundary itself. Because `lt` is exclusive, the end boundary must be the day **after** the last date you want to include.

## Sum only today's entries

This example sums field ID `6` for all entries submitted today, based on each entry's creation date. Replace `id="4"` with your form ID and `{Your Field:6}` with the merge tag for the field you're summing.

```
[gravitymath]
[gravitymath2 scope="form" id="4" filter="filter_date_created=tomorrow&op_date_created=lt"] {Your Field:6} [/gravitymath2]
-
[gravitymath2 scope="form" id="4" filter="filter_date_created=today&op_date_created=lt"] {Your Field:6} [/gravitymath2]
[/gravitymath]
```

```
[gravitymath]
[gravitymath2 scope="form" id="4" filter="filter_date_created=tomorrow&op_date_created=lt"] {Your Field:6} [/gravitymath2]
-
[gravitymath2 scope="form" id="4" filter="filter_date_created=today&op_date_created=lt"] {Your Field:6} [/gravitymath2]
[/gravitymath]
```

How this works:

- The first inner shortcode sums every entry created **before tomorrow** (midnight) — i.e. everything up to and including today.
- The second inner shortcode sums every entry created **before today** (midnight) — i.e. everything from yesterday and earlier.
- The outer `[gravitymath]` subtracts the second from the first, leaving only entries created today.

The `today` and `tomorrow` tokens resolve to midnight on their respective days, so the math lines up cleanly at the day boundary.

## Sum entries between two specific dates

Use this pattern when you need a fixed date range — for example, a monthly report or a custom reporting window. This example covers 2026-04-15 through 2026-04-20 inclusive:

```
[gravitymath]
[gravitymath2 scope="form" id="4" filter="filter_date_created=2026-04-21&op_date_created=lt"] {Your Field:6} [/gravitymath2]
-
[gravitymath2 scope="form" id="4" filter="filter_date_created=2026-04-15&op_date_created=lt"] {Your Field:6} [/gravitymath2]
[/gravitymath]
```

```
[gravitymath]
[gravitymath2 scope="form" id="4" filter="filter_date_created=2026-04-21&op_date_created=lt"] {Your Field:6} [/gravitymath2]
-
[gravitymath2 scope="form" id="4" filter="filter_date_created=2026-04-15&op_date_created=lt"] {Your Field:6} [/gravitymath2]
[/gravitymath]
```

Note two things:

- The **end boundary is 2026-04-21**, not 2026-04-20. Because `lt` is exclusive, you need to pass the day after your last included date.
- The **start boundary is 2026-04-15** — the first date you want to include. `lt 2026-04-15` excludes entries from that day, which is then cancelled out because those entries are also excluded from the end-boundary total.

## Date format: use YYYY-MM-DD

When passing explicit dates into the `filter` parameter, use `YYYY-MM-DD` format (e.g. `2026-04-21` ). Other formats such as `d/m/Y` (e.g. `21/04/2026` ) may not parse reliably, even when that format is what your form's date field displays to users. The `filter_date_created` comparison runs against the stored entry timestamp, not the displayed format.

The `today` and `tomorrow` relative tokens also work and resolve to midnight of the matching day.

## Filtering by a date field in the form, not the submission date

The examples above filter on `filter_date_created` , which is Gravity Forms' built-in entry creation timestamp. If you want to filter on a date field inside the form itself (for example, an "Event date" field with ID `12` ), swap the key:

```
filter="filter_12=2026-04-21&op_12=lt"
```

```
filter="filter_12=2026-04-21&op_12=lt"
```

Use the field ID in place of `date_created` , and date values in `YYYY-MM-DD` format.

## Troubleshooting

**Symptom:** The shortcode outputs `0` or a blank value.

**Cause:** Most often the date format. The `filter` parameter silently fails when it can't parse the date.

**Fix:** Re-enter the date in `YYYY-MM-DD` format. If it still fails, enable [GravityMath debugging](https://www.gravitykit.com/docs/general-help/downloads/installing-activating-and-updating-gravitykit-plugins/) to see how the shortcode is being parsed.

**Symptom:** The result is off by one day's worth of entries.

**Cause:** The end boundary is set to the last day you want included, not the day after.

**Fix:** Because `op_date_created=lt` excludes the boundary, the end date must be the day **after** your last included date. For "through 2026-04-20," use `2026-04-21` .

**Symptom:** The filter parameter is ignored entirely.

**Cause:** Missing or incorrect `scope` set.

**Fix:** The `filter` parameter only works with `scope="form"` or `scope="view"` . Pick one and specify the matching form or View `id` .

## Related

- [Math filters: How to target a specific field value](https://www.gravitykit.com/docs/gravitymath/how-to-target-a-specific-field-value-with-gvmath-filters/) — full `filter` syntax reference, including operators and multi-field conditions.
- [Nested calculations in GravityMath](https://www.gravitykit.com/docs/gravitymath/nested-calculations/) — the nesting pattern this article builds on.
- [How to Calculate the Sum of a Field in Gravity Forms](https://www.gravitykit.com/docs/gravitymath/how-to-calculate-the-sum-of-a-field-in-gravity-forms/) — the starting point if you just need a running total with no date filtering.
- [The  Shortcode](https://www.gravitykit.com/docs/gravitymath/math-shortcode/) — full shortcode attribute reference.