# 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';
```
