Skip to content

getQuarterForDateTime

getQuarterForDateTime(value: string): number
import { getQuarterForDateTime } from "@northguild/gmt/plain/calculate";

Return the quarter of the year (1-4) for a given ISO datetime.

  • Returns the quarter (1-4) containing the input datetime.
  • Q1 = months 1-3, Q2 = months 4-6, Q3 = months 7-9, Q4 = months 10-12.
  • Validates input using isValidDateTime.
Parameter Type Description
value string ISO PlainDateTime string

number (1-4) or null for invalid input

getQuarterForDateTime("2024-01-15T12:00:00") // 1
getQuarterForDateTime("2024-04-15T12:00:00") // 2
getQuarterForDateTime("2024-07-15T12:00:00") // 3
getQuarterForDateTime("2024-10-15T12:00:00") // 4
getQuarterForDateTime("invalid") // null

plain/calculate/getQuarterForDateTime.ts