Skip to content

compareYearMonths

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.
ParameterTypeDescription
astringyear-month string
bstringyear-month string

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

import { compareYearMonths } from "@northguild/gmt/plain/compare";
compareYearMonths("2026-09", "2026-10") // -1
output 

plain/compare/compareYearMonths.ts

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else:© 2026 NorthGuild, all rights reserved.