# Filter By Date

You can filter results by `DateTime` and `DateOnly` fields. Filters can include exact dates, specific date ranges, or relative date ranges.

| Type of Filter      | Example                                              |
| ------------------- | ---------------------------------------------------- |
| exact date range    | `q = filter q by year('CloseDate')=='2018';`         |
| specific date range | `q = filter q by year('CloseDate') in [2017..2018];` |
| relative date range | See the examples below.                              |

Examples of relative date range filters:

```nolang

q = filter q by CloseDate in ["last 2 years"];
q = filter CloseDate in ["current fiscal_year".."current day"];
q = filter CloseDate in ["2 fiscal_years ago".."current day"];
```

:::note
Filter with binary comparison operators `==`, `!=`, `<`, `>`, `<=`, and `>=` only after your query’s `foreach` statement, post-projection. For example, include the filter `q = filter q by CloseDate >= "2014-01-01"` post-projection. If you include it pre-projection, the query throws an error. The inability to include filters that use these comparison operators pre-projection is a limitation of the beta release.

You can filter pre- and post-projection with the `IN` comparison operator. The `like` and `matches` operators are not supported for time zone-enabled `DateTime` and `DateOnly` fields.
:::

You can use these relative date keywords:

- `current day`
- `n day(s) ago`
- `n day(s) ahead`
- `current week`
- `n week(s) ago`
- `n week(s) ahead`
- `current month`
- `n month(s) ago`
- `n month(s) ahead`
- `current quarter`
- `n quarter(s) ago`
- `n quarter(s) ahead`
- `current fiscal_quarter`
- `n fiscal_quarter(s) ago`
- `n fiscal_quarter(s) ahead`
- `current year`
- `n year(s) ago`
- `n year(s) ahead`
- `current fiscal_year`
- `n fiscal_year(s) ago`
- `n fiscal_year(s) ago`

**See Also**

- [filter](/docs/analytics/bi-dev-guide-saql/guide/bi-saql-statement-filter.md)
- [Comparison Operators](/docs/analytics/bi-dev-guide-saql/guide/bi-saql-operators-comparison.md)
