---
schema_version: "1"
id: 7aa6165a4e0dac756015db8db7e3c2d07fef0611d65a07f3d29344147423125a
title: Order By Date Part
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-order.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-date-order.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d378a1af8bd08d739d6ab5e9a936a561d880cbdbb403a25db09b3484baff66fb
products:
  - SQL for Analytics Developer Guide
  - analytics
---

# Order By Date Part

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.

```nolang
SELECT EXTRACT(YEAR FROM CloseDate) AS CloseDate_Year, EXTRACT(MONTH FROM CloseDate) AS CloseDate_Month, COUNT(*) AS cnt
FROM "OpportunityFiscalEMTimezoned"
GROUP BY EXTRACT(YEAR FROM CloseDate), EXTRACT(MONTH FROM CloseDate)
ORDER BY cnt DESC
LIMIT 10;
```

| CloseDate_Year | CloseDate_Month | cnt |
| -------------- | --------------- | --- |
| 2015           | 1               | 3   |
| 2015           | 3               | 2   |
| 2015           | 4               | 2   |
| 2015           | 5               | 2   |
| 2014           | 12              | 1   |
| 2015           | 2               | 1   |
| 2015           | 6               | 1   |
| 2015           | 8               | 1   |
| 2015           | 10              | 1   |
| 2015           | 11              | 1   |
