> ## Documentation Index
> Fetch the complete documentation index at: https://docs.invoca.com/llms.txt
> Use this file to discover all available pages before exploring further.

# About Date Formulas

> Date formulas apply date-related functions to your Invoca formulas, useful for comparing data across date periods.

Date functions are useful when you want to compare data collected between two date periods. Date formulas let you apply date-related functions within your formulas.

## Date formulas

```text theme={null}
add_days, add_minutes, add_months, add_seconds, add_weeks, add_years,
date, day, day_number_of_quarter, day_number_of_week, day_number_of_year,
day_of_week, diff_days, diff_time, hour_of_day, is_weekend, month,
month_number, month_number_of_quarter, now, quarter_number,
start_of_month, start_of_quarter, start_of_week, start_of_year, time,
today, week_number_of_month, week_number_of_quarter, week_number_of_year,
year
```

| Function                  | Description                                                                            | Example                                                      |
| :------------------------ | :------------------------------------------------------------------------------------- | :----------------------------------------------------------- |
| `add_days`                | Adds the specified number of days to a date                                            | `add_days (01/30/2015, 5) = 02/04/2015`                      |
| `add_minutes`             | Adds minutes to a date, datetime, or time                                              | `add_minutes (01/30/2015 00:10:20, 5) = 01/30/2015 00:15:20` |
| `add_months`              | Adds months to a date                                                                  | `add_months (01/30/2015, 5) = 06/30/2015`                    |
| `add_seconds`             | Adds seconds to a date/datetime/time                                                   | `add_seconds (01/30/2015 00:00:00, 5) = 01/30/2015 00:00:05` |
| `add_weeks`               | Adds weeks to a date                                                                   | `add_weeks (01/30/2015, 2) = 02/13/2015`                     |
| `add_years`               | Adds years to a date                                                                   | `add_years (01/30/2015, 5) = 01/30/2020`                     |
| `date`                    | Returns the date portion of a date                                                     | `date (home visit)`                                          |
| `day`                     | Returns the day of the month (1-31)                                                    | `day (01/15/2014) = 15`                                      |
| `day_number_of_quarter`   | Day number within a quarter. Optional `'fiscal'` / `'calendar'` (default `'calendar'`) | `day_number_of_quarter (01/30/2015) = 30`                    |
| `day_number_of_week`      | Day number within a week; Monday = 1, Sunday = 7                                       | `day_number_of_week(01/15/2014) = 3`                         |
| `day_number_of_year`      | Day number within a year (1-366). Optional `'fiscal'` / `'calendar'`                   | `day_number_of_year (01/30/2015) = 30`                       |
| `day_of_week`             | Day of the week for a date                                                             | `day_of_week (01/30/2015) = Friday`                          |
| `diff_days`               | Difference between two dates, in days (rounded down)                                   | `diff_days (01/15/2014, 01/17/2014) = -2`                    |
| `diff_time`               | Difference between two dates, in seconds                                               | `diff_time (01/30/2014, 01/31/2014) = -86,400`               |
| `hour_of_day`             | Hour of the day for a date                                                             |                                                              |
| `is_weekend`              | `true` if the date is a Saturday or Sunday                                             | `is_weekend (01/31/2015) = true`                             |
| `month`                   | Month from the date                                                                    | `month (01/15/2014) = January`                               |
| `month_number`            | Month number (1-12). Optional `'fiscal'` / `'calendar'`                                | `month_number (09/20/2014) = 9`                              |
| `month_number_of_quarter` | Month number (1-3) within a quarter. Optional `'fiscal'` / `'calendar'`                | `month_number_of_quarter (02/20/2018) = 2`                   |
| `now`                     | Current date and time, in your locale's format                                         | `now ()`                                                     |
| `quarter_number`          | Quarter number (1-4). Optional `'fiscal'` / `'calendar'`                               | `quarter_number (04/14/2014) = 2`                            |
| `start_of_month`          | First day of the month, as `MMM yyyy`                                                  | `start_of_month (01/31/2015) = Jan FY 2015`                  |
| `start_of_quarter`        | First day of the quarter. Optional `'fiscal'` / `'calendar'`                           | `start_of_quarter (04/30/2014) = Apr 2014`                   |
| `start_of_week`           | First day of the week                                                                  | `start_of_week (01/31/2020) = 01/27/2020`                    |
| `start_of_year`           | First day of the year. Optional `'fiscal'` / `'calendar'`                              | `start_of_year (04/30/2014) returns Jan 2014`                |
| `time`                    | Time portion of a date                                                                 | `time (1/31/2002 10:32) = 10:32`                             |
| `today`                   | Current date, in your locale's format                                                  | `today ()`                                                   |
| `week_number_of_month`    | Week number within a month                                                             | `week_number_of_month(03/23/2017) = 3`                       |
| `week_number_of_quarter`  | Week number within a quarter. Optional `'fiscal'` / `'calendar'`                       | `week_number_of_quarter (01/31/2020) = 5`                    |
| `week_number_of_year`     | Week number within a year. Optional `'fiscal'` / `'calendar'`                          | `week_number_of_year (01/17/2014) = 3`                       |
| `year`                    | Year from a date. Optional `'fiscal'` / `'calendar'`                                   | `year (01/15/2014) = 2014`                                   |

## Calculate date formulas

Date formulas are useful for comparing data from different periods.

### Example 1: this week vs. last week

```text theme={null}
this week = week ( today () ) - week (date)
last week = diff_days ( week ( today () ), week ( date ) )
```

### Example 2: percent increase over the last period

1. Create the formula:
   ```text theme={null}
   this week revenue = sum ( if ( this week ) then revenue else 0 )
   ```
2. Create the formula:
   ```text theme={null}
   last week revenue = sum ( if (last week ) then revenue else 0 )
   ```
3. Use [nested formulas](/s/article/nested-formulas) to calculate the percent increase with a parent formula:
   ```text theme={null}
   percent increase = ( ( this week revenue - last week revenue) / last week revenue ) * 100
   ```

## Fiscal and Gregorian calendars

For the functions listed below, you can specify either `fiscal` or Gregorian `calendar` as the basis for date calculations. If you don't specify a calendar type, the formula defaults to standard Gregorian, with the year starting in January.

```text theme={null}
day_number_of_quarter, day_number_of_year, month_number,
month_number_of_quarter, quarter_number, start_of_quarter,
start_of_year, week_number_of_quarter, week_number_of_year, year
```

## Where to go next

* [Formula function reference](/s/article/formula-function-reference)
* [Nested formulas](/s/article/nested-formulas)
