# sortDates

Industry: Core

## Signature

```ts
sortDates(dates: string[], order?: "asc" | "desc"): string[]
```

Sort an array of PlainDate values in ascending or descending order.

- Returns empty array if no valid dates.
- Validation is performed on each item in the array.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `dates` | `string[]` | Array of ISO PlainDate strings (e.g. "2024-03-10") |
| `order` | `"asc"` \| `"desc"` | "asc" for ascending (earliest first) \| "desc" for descending (latest first) |

## Returns

Sorted array of date strings

## Examples

```ts
import { sortDates } from "@northguild/gmt/plain/calculate";

sortDates(["2024-03-10", "2024-01-01", "2024-02-15"]) // ["2024-01-01", "2024-02-15", "2024-03-10"]
```

## Source

[plain/calculate/sortDates.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/plain/calculate/sortDates.ts)
