Skip to content

previousWeekday

  • The core functions, which every industry uses.
previousWeekday(value: string, dayOfWeek: number, options?: { inclusive?: boolean; }): string

Return a PlainDate ISO string for the previous occurrence of dayOfWeek before value (or on it, with inclusive: true).

  • dayOfWeek uses Temporal’s ISO numbering: 1 (Monday) through 7 (Sunday), consistent with getDayOfWeek/parseDayOfWeekFromDate.

  • Returns "" on invalid input. Migrating from date-fns: its eight previous* functions map to one parameterized call. date-fns numbers days 0 (Sunday) to 6 (Saturday), so previousDay’s 0 becomes 7.

    date-fnsgmt
    previousMondaypreviousWeekday(value, 1)
    previousTuesdaypreviousWeekday(value, 2)
    previousWednesdaypreviousWeekday(value, 3)
    previousThursdaypreviousWeekday(value, 4)
    previousFridaypreviousWeekday(value, 5)
    previousSaturdaypreviousWeekday(value, 6)
    previousSundaypreviousWeekday(value, 7)
    previousDay(v, n)previousWeekday(value, n === 0 ? 7 : n)
ParameterTypeDescription
valuestringISO PlainDate string
dayOfWeeknumbertarget ISO day of week (1-7, Monday-Sunday)

options

Whether value itself can be the result

OptionTypeDefaultDescription
inclusive?booleanfalseWhether value counts when it already falls on dayOfWeek. true returns value unchanged; false goes back a full week.

ISO PlainDate string for the previous occurrence of dayOfWeek, or "" on invalid input

import { previousWeekday } from "@northguild/gmt/plain/calculate";
previousWeekday("2024-03-15", 5) // "2024-03-08" (2024-03-15 is already a Friday, so it goes back a full week)
output 

plain/calculate/previousWeekday.ts

Accessibility
© 2026 NorthGuild · Licences

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.