---
schema_version: "1"
id: 104e42ccd7a523473153f4adf20161547378b96d3420fedb9d7df5f515986a6e
title: Group By Date
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/concept/bi-saql-functions-timezone-group.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-functions-timezone-group.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7843a955f7e3b38b765858d51a147c88cc220db629f58b66e550c1d5d8d820c3
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# Group By Date

You can group the result of your SAQL query by `DateTime` and `DateOnly` fields.

```nolang
q = group q by 'CloseDate';
```

`CloseDate` can be `DateTime` or `DateOnly`. You can also group by date parts. For example, you can group orders by year and then month.

```nolang
q = group q by year('OrderDate'), month('OrderDate');
```

You can use the `DateTime` or `DateOnly` field to cogroup two datasets. For example, you can group two datasets by year.

```nolang
a = load dataset1;
b = load dataset2;
c = group a by year('CloseDate'), b by year('CloseDate');
e = foreach c generate year(a.'CloseDate') as 'CloseDate A', year(b.'CloseDate') as
'Close Date B', sum(a.Amount) as 'Sum of Amount';
```
