---
schema_version: "1"
id: e57665d1b12c29469fd508b1ef47d23f33be840df5517424659c8ef09177286f
title: Year, Quarter, or Month Functions
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/sales/264-0-0/spiff_functions_date_period.md
canonical_url: https://help.salesforce.com/s/articleView?id=sales.spiff_functions_date_period.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: c269d8a0ecce12d09980e61e049fc2a125befea7d9f65d87f7de2fd6e816d2fe
description: Functions for the beginning and end of a year, quarter, or month in Salesforce Spiff help you compare data during the specified time period. Combine these functions with other functions that process dates.
products:
  - Sales Cloud
  - Sales Enablement
release: "264"
---
# Year, Quarter, or Month Functions

Functions for the beginning and end of a year, quarter, or month in Salesforce Spiff help you compare data during the specified time period. Combine these functions with other functions that process dates.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available for an additional cost in: <strong>Professional</strong> Edition with Web Services API Enabled</td></tr></tbody></table>

## Find the Beginning of Time Period

To find the beginning of the year relative to the statement period, use the statement period start or end date for the `beginning_of_year()` function's input. This calculation changes dynamically in each period and returns the beginning of year date associated with the statement period start date.

```
=beginning_of_year(statement_period.start_date)
```

For February 2024 or November 2024, this function returns January 1, 2024. For December 2023, this function returns January 1, 2023.

Here are a few other examples.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:20%">
          <col style="width:80%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d64800e95">Date to Find</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d64800e98">Formula</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of the previous month</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 "><code>=months_ago(statement_period.start_date, 1)</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of the previous quarter</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 "><code>=beginning_of_quarter(days_ago(beginning_of_quarter(statement_period.start_date), 1))</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of the previous statement period</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 ">
              <p><code>=beginning_of_month(EndOfLastStatementPeriod)</code>
              </p>
              <p style="margin-bottom:0;">This example requires a separate EndOfLastStatementPeriod calculation.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of the previous year</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 "><code>=beginning_of_year(days_ago(beginning_of_year(statement_period.start_date), 1))</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of Q1 in the previous year</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 ">
              <p><code>=months_ago(BeginningOfQ1, 12)</code>
              </p>
              <p style="margin-bottom:0;">This example requires a separate BeginningOfQ1 calculation.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of Q2 in the current year</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 ">
              <p><code>=days_ago(EndOfQ1, -1)</code>
              </p>
              <p style="margin-bottom:0;">This example requires a separate EndOfQ1 calculation.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of the current quarter</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 "><code>=beginning_of_quarter(statement_period.start_date)</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e95 ">Beginning of two monthly statement periods ago</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e98 "><code>=months_ago(statement_period.start_date, 2)</code></td>

          </tr>
        </tbody>
      </table>

## Find the End of Time Period

Test that a function works as expected for a specific time period. For example, let's say you have this formula.

```
=statement_period.end_date = end_of_year(statement_period.end_date)
```

If the statement period is December, this formula returns `true`. For all periods, this formula returns `false`.

![Formula with end\_of\_year function that returns true for December](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-sales-sales_performance_management-264-0-0-production-enus/b1f2feb4-26b8-444f-97f7-be2349869d93/sales_performance_management/images/spiff/spiff_functions_date_eoy.png)

And end function can help you pay out only at certain times, which is especially useful if a rep receives an annual bonus. Wrap the calculation in an `if` statement that returns a `1` if true or a `0` if false. Then multiply by another calculation, and make sure that `0` is returned if the day isn’t the end of the month, quarter, or year.

```
=if(IsEndOfQuarter, 1, 0) * QuarterlyCommission
```

Here are a few other examples.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:20%">
          <col style="width:80%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d64800e262">Date to Find</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d64800e265">Formula</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of the previous month</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 "><code>=days_ago(statement_period.start_date, 1)</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of the previous quarter</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 "><code>=days_ago(beginning_of_quarter(statement_period.start_date), 1)</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of the previous statement period</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 "><code>=days_ago(statement_period.start_date, 1)</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of the previous year</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 "><code>=days_ago(beginning_of_year(statement_period.start_date), 1)</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of Q1 in the current year</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 "><code>=end_of_quarter(beginning_of_year(statement_period.start_date))</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of Q1 in the previous year</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 ">
              <p><code>=months_ago(EndOfQ1, 12)</code>
              </p>
              <p style="margin-bottom:0;">This example requires a separate EndOfQ1 calculation.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of Q2 in the current year</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 ">
              <p><code>=end_of_quarter(BeginningOfQ2)</code>
              </p>
              <p style="margin-bottom:0;">This example requires a separate BeginningOfQ2 calculation.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of the current quarter</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 "><code>=end_of_quarter(statement_period.start_date)</code></td>

          </tr>
          <tr class="">
            <td data-label="Date to Find" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e262 ">End of two monthly statement periods ago</td>

            <td data-label="Formula" class="slds-cell-wrap" style="vertical-align:top;" headers="d64800e265 ">
              <p><code>=days_ago(BeginningOfLastMonth, 1)</code>
              </p>
              <p style="margin-bottom:0;">This example requires a separate BeginningOfLastMonth calculation.</p>
            </td>

          </tr>
        </tbody>
      </table>

## Calculate Half of a Year

Create these worksheet calculations.

```
BeginYear = beginning_of_year(statement_period.start_date)
```

```
MidYear = months_ago(BeginYear, -6)
```

```
EndYear = end_of_year(statement_period.start_date)
```

Then, create these worksheet calculations that determine whether a date falls into the first or second half of the year.

```
HalfYearStart = if(statement_period.start_date < MidYear, BeginYear, MidYear)
```

```
HalfYearEnd = if(statement_period.start_date > MidYear, days_ago(MidYear, 1), EndYear)
```

Finally, create a data filter.

```
=date_between?(CloseDate, HalfYearStart, HalfYearEnd)
```

## Manage Fiscal Years

To switch to a new fiscal period without having to change other values, use the `beginning_of_year()` and `beginning_of_fiscal_year()` functions in filters to pivot after a specific date. For example, consider this definition of the InYear filter with these requirements.

- Calendar year 2021 or prior
- A 13-month year from January 1, 2022 to January 31, 2023
- A 12-month fiscal year that begins February 1, 2023

```
(CloseDate <= statement_period.end_date) 
            AND 
            ( 
            ((CloseDate >= beginning_of_year(statement_period.start_date)) AND (CloseDate <= date("2021-12-31")))
            OR
            ((CloseDate >= beginning_of_fiscal_year(statement_period.start_date)) AND (CloseDate >= date("2023-02-01")))
            OR
            ((CloseDate >= date("2022-01-01" ))  AND (CloseDate < date("2023-02-01" )))
            )
```

## Compare Date and Date & Time Values

Some fields in Spiff use only Date values but other fields have Date & Time values. You can't compare these values directly unless you convert one type to another. The `beginning_of_day()` and `end_of_day()` functions help convert Date values to Date & Time values. For example, find the Date & Time value of the EndOfPeriod date.

```
=end_of_day(EndOfPeriod)
```

#### See Also

- [beginning\_of\_fiscal\_quarter](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_beginning_of_fiscal_quarter.htm&release=264.0.0&type=5 "Returns the first day of the fiscal quarter for a specific date or time in Salesforce Spiff. The return format is YYYY-MM-DD. If you haven't specified fiscal year dates in Spiff, this function falls back to a standard calendar year.")
- [beginning\_of\_fiscal\_year](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_beginning_of_fiscal_year.htm&release=264.0.0&type=5 "Returns the first day of the fiscal year for a specific date or time in Salesforce Spiff. The return format is YYYY-MM-DD. If you haven't specified fiscal year dates in Spiff, this function falls back to a standard calendar year.")
- [beginning\_of\_month](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_beginning_of_month.htm&release=264.0.0&type=5 "Returns the first day of the month for a specific date or time value in Salesforce Spiff. The return format is YYYY-MM-DD.")
- [beginning\_of\_quarter](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_beginning_of_quarter.htm&release=264.0.0&type=5 "Returns the first day of the quarter for a specific date or time value in Salesforce Spiff. The return format is YYYY-MM-DD. If you've specified fiscal year dates that are different from standard calendar dates, use the beginning_of_fiscal_quarter() function instead.")
- [end\_of\_fiscal\_quarter](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_end_of_fiscal_quarter.htm&release=264.0.0&type=5 "Returns the last day of the fiscal quarter for a specific date or time in Salesforce Spiff. The return format is YYYY-MM-DD. If you haven't specified fiscal year dates in Spiff, this function falls back to a standard calendar year.")
- [end\_of\_fiscal\_year](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_end_of_fiscal_year.htm&release=264.0.0&type=5 "Returns the last day of the fiscal year for a specific date or time in Salesforce Spiff. The return format is YYYY-MM-DD. If you haven't specified fiscal year dates in Spiff, this function falls back to a standard calendar year.")
- [end\_of\_month](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_end_of_month.htm&release=264.0.0&type=5 "Returns the last day of the month for a specific date or time value in Salesforce Spiff. The return format is YYYY-MM-DD.")
- [end\_of\_quarter](https://help.salesforce.com/s/articleView?id=sales.spiff_function_ref_end_of_quarter.htm&release=264.0.0&type=5 "Returns the last day of the quarter for a specific date or time value in Salesforce Spiff. The return format is YYYY-MM-DD. If you've specified fiscal year dates that are different from standard calendar dates, use the end_of_fiscal_quarter() function instead.")