---
schema_version: "1"
id: 9a58dd0c228fd65a2302337d778352a8322b09a996a5a0863fe333ef72a1d525
title: Date Functions for Formulas
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/data/264-0-0/c360_a_batch_transform_date_functions.md
canonical_url: https://help.salesforce.com/s/articleView?id=data.c360_a_batch_transform_date_functions.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: dd8dda5b7b72de1fea5b2e9a4cae49d9ed8e4e8a47256c9d2e7543e68e87a9c7
description: Use date functions to adjust or calculate values from dates. For example, you can add time, find time until, and extract a day of the week from date fields. The arguments for date functions are date fields.
products:
  - Data 360
release: "264"
---
# Date Functions for Formulas

Use date functions to adjust or calculate values from dates. For example, you can add time, find time until, and extract a day of the week from date fields. The arguments for date functions are date fields.

When entering a formula, use the API name of the field in the expression, not the label. The parameters section is surrounded by parentheses. For example, you can enter the following expression.

```
datediff(ClosedDate, CreatedDate)
```

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
      <colgroup>
        <col style="width:22.98850574712644%">
        <col style="width:32.41379310344827%">
        <col style="width:44.59770114942529%">
      </colgroup>
      <thead class="slds-text-title_caps ">
        <tr class="">
          <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d169201e43">Date Function</th>
          <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d169201e46">Description</th>
          <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d169201e49">Syntax</th>
        </tr>
      </thead>
      <tbody>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>add_months</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the date with the specified number of months after the start date.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>add_months(<var>startDate</var>,<var>num_months</var>)</code>
            </p>
            <p><var>startDate</var>
              is the date field calculated on.</p>
            <p style="margin-bottom:0;"><var>num_months</var> is the number of months
              added to the <var>startDate</var>.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>current_date</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the current date. </td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <code>current_date()</code>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>current_timestamp</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the current date and time.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <code>current_timestamp()</code>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>datediff</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the number of days between start date and end date.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>datediff(<var>endDate</var>,<var>startDate</var>)</code>
            </p>
            <p><var>endDate</var>
              is the later of the two dates you are finding the difference
              between.</p>
            <p style="margin-bottom:0;"><var>startDate</var> is the earlier of the two dates you are finding
              the difference between.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>date_add</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the date with the specified number of days after the start date.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>date_add(<var>startDate</var>,<var>num_days</var>)</code>
            </p>
            <p><var>startDate</var> is the date field calculated on.</p>
            <p style="margin-bottom:0;"><var>num_days</var> is the number of days added to the startDate. Only
              static integer values are accepted.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>date_format</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Converts the timestamp to a specified date format.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>date_format(<var>field</var>,'<var>format</var>')</code>
            </p>
            <p><var>field</var>
              is a date field/timestamp or string to be converted to the given
              format.</p>
            <p><var>'format'</var> is the date and time format pattern to
              follow.</p>
            <div>
              <p>Example:
              </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>date_format('2016-04-08', 'y')</code></pre>
              <p> returns
                2016</p>
            </div>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>date_sub</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Removes the specified number of days from the start date.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>date_sub(<var>startDate</var>,<var>num_days</var>)</code>
            </p>
            <p><var>startDate</var> is the date field calculated on.</p>
            <p style="margin-bottom:0;"><var>num_days</var> is the number of days subtracted from the startDate.
              Only static integer values are accepted.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>date_trunc</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Resets the specified part of the timestamp, and all portions after it, to zero (or 01
            for date and year). Specify the portion of the timestamp, fmt, with ‘year’, ‘quarter’,
            ‘month’, ‘week’, ‘day’, ‘hour’, ‘minute’, or ‘second’. For example, dateTrunc for ‘year’ of
            2019-05-01 12:31:32 returns 2019-01-01 00:00:00. If your data is date and not datetime, use
            the trunc function instead.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>date_trunc(<var>'format'</var>,<var>timestamp</var>)</code>
            </p>
            <p><var>'format'</var>
              is the date and time format pattern to follow.</p>
            <p><var>timestamp</var> is a
              date/timestamp or string which is returned as a UNIX timestamp.</p>
            <div>
              <p>Example:
              </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>date_trunc('week',CloseDate)</code></pre>
              <p> returns the Monday
                of the week of the Close Date.</p>
            </div>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>day</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the day of the month component of the date/timestamp.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>day(<var>date</var>)</code>
            </p>
            <p style="margin-bottom:0;"><var>date</var> is the date field to
              extract the day of the month from.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>dayofmonth</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the day of the month component of the date/timestamp.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>dayofmonth(<var>date</var>)</code>
            </p>
            <p style="margin-bottom:0;"><var>date</var> is the date field
              to extract the day of the month from.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>dayofweek</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the day of the week component of the date/timestamp. 1 = Sunday, 2 = Monday,
            ..., 7 = Saturday.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>dayofweek(<var>date</var>)</code>
            </p>
            <p style="margin-bottom:0;"><var>date</var> is the date field to
              extract the day of the week from.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>dayofyear</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the day of year component of the date/timestamp.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>dayofyear(<var>date</var>)</code>
            </p>
            <p style="margin-bottom:0;"><var>date</var> is the date field to
              extract the day of the year from.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>months_between</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the number of months between two timestamps. Calculates the difference based on
            31 days per month rounded to 8 digits unless roundOff=false. If timestamp1 is later than
            timestamp2, the result is positive. If timestamp1 and timestamp2 are on the same day of the
            month, or both are the last day of the month, the result is an integer and the time of day is
            ignored.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>months_between(<var>timestamp2</var>,<var>timestamp1</var>,<var>roundOff(optional)</var>)</code>
            </p>
            <p><var>timestamp2</var>
              is one of the timestamps to compare.</p>
            <p><var>timestamp1</var> is the other
              timestamp to compare.</p>
            <p style="margin-bottom:0;"><var>roundOff(optional)</var> is a boolean that
              determines whether to round the result. This parameter is optional.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>now</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the current date and time in the specified format.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <code>now()</code>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>to_date</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Converts the date string to the specified date format. Returns null with invalid
            input.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>to_date(<var>field</var>,<var>'format(optional)'</var>)</code>
            </p>
            <p><var>field</var>
              is a date string field that you want to convert.</p>
            <p style="margin-bottom:0;"><var>'format(optional)'</var>
              is the date and time format pattern to follow. This parameter is optional. The function
              follows casting rules to a date if format isn’t included.</p>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>to_timestamp</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Converts the timestamp string to the specified timestamp format.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>to_timestamp(<var>field</var>,<var>'format(optional)'</var>)</code>
            </p>
            <p><var>field</var> is a timestamp string field that you want to convert.</p>
            <p><var>'format(optional)'</var> is the timestamp format pattern to follow.
              This parameter is optional. The function follows casting rules to a timestamp if
              format isn’t included. </p>
            <div>
              <p>For example, <code>'M'</code> or
                <code>'L'</code> is the month number in a year starting from 1.
              </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x" id="c360_a_batch_transform_date_functions__codeblock_arn_ntx_22c"><a name="c360_a_batch_transform_date_functions__codeblock_arn_ntx_22c"><!-- --></a><code>to_timestamp('2020-01-01', 'M')</code></pre>
              <p>
                returns </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x" id="c360_a_batch_transform_date_functions__codeblock_vxl_ptx_22c"><a name="c360_a_batch_transform_date_functions__codeblock_vxl_ptx_22c"><!-- --></a><code>1</code></pre>
              <p> The value YYYY/MM/DD is
                a 4-digit year, 2 digit month, and day of the month.
              </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x" id="c360_a_batch_transform_date_functions__codeblock_bc2_h5x_22c"><a name="c360_a_batch_transform_date_functions__codeblock_bc2_h5x_22c"><!-- --></a><code>TO_TIMESTAMP('2024/12/10 11:10:15', 'YYYY/MM/DD HH:MI:SS')</code></pre>
              <p>returns</p>
            </div>
            <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x" id="c360_a_batch_transform_date_functions__codeblock_dnf_j5x_22c"><a name="c360_a_batch_transform_date_functions__codeblock_dnf_j5x_22c"><!-- --></a><code>10-DEC-24 11.10.15.000000000 AM</code></pre>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>to_unix_timestamp</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Returns the UNIX timestamp of the specified time.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>to_unix_timestamp(<var>timestamp</var>,<var>format(optional</var>)</code>
            </p>
            <p><var>timestamp</var> is a date/timestamp or string which is returned as a
              UNIX timestamp.</p>
            <p><var>format(optional)</var> is the date/time format pattern to follow.
              <var>format(optional)</var> is ignored if <var>timestamp</var> is
              not a string. Default value is "<code>yyyy-MM-dd HH:mm:ss</code>". This
              parameter is optional.
            </p>
            <div>
              <p>Example: </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>to_unix_timestamp('2016-04-08', 'yyyy-MM-dd')</code></pre>
              <p>
                returns </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>1460098800</code></pre>
            </div>
          </td>

        </tr>
        <tr class="">
          <td data-label="Date Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e43 ">
            <code>trunc</code>
          </td>

          <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e46 ">Replaces the specified portion of the timestamp, and all portions after, with
            zeroes.</td>

          <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d169201e49 ">
            <p>
              <code>trunc(<var>field</var>,<var>'format(optional)'</var>)</code>
            </p>
            <p><var>field</var>
              is a timestamp field.</p>
            <p><var>'format(optional)'</var> specifies the part of the
              timestamp to truncate. Accepted values are "<code>YEAR</code>",
              "<code>YYYY</code>", "<code>YY</code>",
              "<code>MON</code>", "<code>MONTH</code>",
              "<code>MM</code>", "<code>DAY</code>",
              "<code>DD</code>", "<code>HOUR</code>",
              "<code>MINUTE</code>", "<code>SECOND</code>", "<code>WEEK</code>", and "<code>QUARTER</code>".</p>
            <div>
              <p>Example:
              </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>trunc('2015-03-05T09:32:05.359', 'MM')</code></pre>
              <p> returns
              </p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>2015-03-01T00:00:00</code></pre>
            </div>
          </td>

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

## Date and Time Function Considerations

Keep these behaviors in mind when working with date and time functions.

- These functions are relative to when the batch data transform runs.
    - `now`
    - `current_date`
    - `current_timestamp`
    - `to_unix_timestamp`
- All date and datetime functions are based on the UTC time zone.
- When Custom Time Zone Support is enabled, date functions and DateTime functions are separated. When it’s disabled, the functions are grouped together.