# compareYearMonths

:::caution[Unreleased]
Not in `@northguild/gmt` 1.20.0 on npm yet. It is on `main` and ships in the next release.
:::

## Signature

```ts
compareYearMonths(a: string, b: string): number | null
```

Compare two year-month strings (`YYYY-MM`) in calendar order: year first, then month.

- Accepts both year forms, so `2026-10` and `+002026-10` compare equal.
- Negative years sort before year 0: `-000001-12` is before `0000-01`.
- Returns `null` if either input is invalid or not in the ISO calendar.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `a` | `string` | year-month string |
| `b` | `string` | year-month string |

## Returns

-1, 0, or 1, or null on invalid input

## Examples

```ts
import { compareYearMonths } from "@northguild/gmt/plain/compare";

compareYearMonths("2026-09", "2026-10") // -1
```

## Source

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