Skip to content

parseWeekFromDateTime

parseWeekFromDateTime(value: string, optionsArg?: { weekStartsOn?: "monday" | "sunday"; }): number | null

Return the week number for a given ISO 8601 datetime string.

  • The week is the week of the week-year, 1–53, under either numbering — see getWeekNumber.
  • Returns null for invalid input.
ParameterTypeDescription
valuestringISO 8601 datetime string

optionsArg

How weeks are numbered

OptionTypeDefaultDescription
weekStartsOn?"monday" | "sunday""monday"The first day of the week, which sets how the week is numbered. "monday" gives the ISO 8601 week number, where week 1 holds the year’s first Thursday; "sunday" gives the UTS #35 week number with a Sunday first day and one minimal day, where week 1 holds 1 January. Any other value returns null.

Week number (1-53) or null on invalid input

import { parseWeekFromDateTime } from "@northguild/gmt/plain/parse";
parseWeekFromDateTime("2024-01-01T12:00:00") // 1
output 

plain/parse/parseWeekFromDateTime.ts