---
schema_version: "1"
id: 8626087a38971f5271fdcc1ccc91175bf6415111683fcc1b852e71f6f598aa89
title: Date Functions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_sql/guides/bi-sql-date-intro.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-intro.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: f42eaa0d75be848a919fff1e14355eb7c3c9e5e8e0dc2e0a71ddbbd67fc8f60e
products:
  - SQL for Analytics Developer Guide
  - analytics
---

# Date Functions

SQL for CRM Analytics supports `DateTime`, `DateOnly`, and `Date` date types. If you’re familiar with standard SQL, the `DateOnly` type corresponds with SQL’s `Date` type and the `DateTime` type corresponds with SQL's `Timestamp` type. `DateTime` and `DateOnly` have custom time zone support. If your org doesn’t support custom time zones, then use the `Date` type, which supports GMT date information only.

A `DateTime` date type follows this format.

```nolang
DateTimeFormat = "2006-01-02 15:04:05"
```

A `DateOnly` date type follows this format.

```nolang

DateOnlyFormat = "2006-01-02"
```

- **[Access Parts of a Date](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-access.md)**


    Use the `EXTRACT()` function to access parts of a date. You can use `EXTRACT()` in projections, filtering, grouping and ordering.

- **[Project a Date Field](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-project.md)**


    To project a date field of type `DateTime`, use the `EXTRACT()` function on the date field in the `SELECT` statement.

- **[Filter By Date Parts or Date Field](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-filter.md)**


    To filter by a date part, use the `WHERE` clause with the `EXTRACT()` function, and pass it the desired date parts (year, month, or day). To filter by a date field, use the `WHERE` clause with a logical operator.

- **[Group By Date Part](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-group.md)**


    To group by date part, use the `GROUP BY` clause and the `EXTRACT()` function. Pass `EXTRACT()` the date parts to isolate.

- **[Order By Date Part](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-order.md)**


    To order by date part, use `EXTRACT()` on the date field with the `ORDER BY` clause. The query returns the count of rows containing these same values and orders the results by count descending.

- **[Project a Custom Fiscal Date Part](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-cfy.md)**


    To project a custom fiscal date part, pass custom fiscal date parts to the `EXTRACT()` function.

- **[Day in Week, Month, Quarter or Year Functions](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-order-functions.md)**


    Use the following functions to find the position of a day within a week, month, quarter, or year.

- **[First and Last Day in the Week, Month, Quarter or Year Functions](https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-first-last-functions.md)**


    Use the following functions to find the first and last week, month, quarter, or year for both standard and fiscal calendars. These functions accept `DateTime`, `DateOnly`, and legacy input values. They return the same type as the input value.
