# sortDateTimes

Industry: Core

## Signature

```ts
sortDateTimes(dateTimes: string[], order?: "asc" | "desc"): string[]
```

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

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

## Parameters

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

## Returns

Sorted array of datetime strings

## Examples

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

sortDateTimes(["2024-03-10T12:00:00", "2024-01-01T08:00:00", "2024-02-15T15:30:00"]) // ["2024-01-01T08:00:00", "2024-02-15T15:30:00", "2024-03-10T12:00:00"]
```

## Source

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