Skip to content

Date Helpers

Utility functions for working with date operations.

FunctionDescription
add / subtract (date arithmetic)native JS Temporal.PlainDate.prototype.add(duration) / .subtract(duration) (Temporal (Stage 3))
addDaysAdds days to a date.
addMonthsAdds months to a date.
addYearsAdds years to a date.
clampDateClamps a date to a [min, max] range.
compareComparison of two dates.
compare (ordering)native JS Temporal.PlainDate.compare(a, b) / Temporal.Instant.compare(a, b) (Temporal (Stage 3))
daysInMonthReturns the number of days in the given month of the given year.
differenceCalculates the difference between two dates in the specified unit.
eachDayReturns an array of `Date` objects for each day from `start` to `end` (inclusive).
eachMonthReturns an array of `Date` objects for the first day of each month from `start` to `end` (inclusive).
endOfReturns a new `Date` set to the **end** of the given unit.
ensureDateSafely converts a date-like value to a valid `Date` object, or returns `null`.
formatDurationFormats a duration in milliseconds as a compact human-readable string.
formatInTimezoneFormats a date in a specific IANA timezone using `Intl.DateTimeFormat`.
from (parse temporal string)native JS Temporal.Instant.from(str) / Temporal.PlainDate.from(str) / etc. (Temporal (Stage 3))
fromMillisCreates a `Date` from a timestamp in **milliseconds**.
fromSecondsCreates a `Date` from a timestamp in **seconds**.
getTimezoneOffsetReturns the UTC offset **in minutes** for the given IANA timezone at a specific point in time.
isBusinessDayChecks whether a date falls on a business day (i.e.
isLeapYearReturns `true` if the given year is a leap year.
isSameDayChecks if two dates are the same day.
isSameMonthChecks if two dates are in the same month (and year).
isSameYearChecks if two dates are in the same year.
isTimestampInSecondsChecks if a timestamp is likely in seconds (Java/Unix style) vs milliseconds (JavaScript style)
isValidChecks if a value is a valid Date instance (not `Invalid Date`).
isValidDateStringChecks whether a string can be parsed into a valid `Date`.
isWeekendChecks whether a date falls on a weekend day.
isWithinRangeChecks whether a date falls within a range (inclusive on both ends).
listTimezonesReturns the list of IANA timezone identifiers supported by the runtime.
normalizeTimestampConverts a timestamp to JavaScript milliseconds format
now (date/time/instant)native JS Temporal.Now.instant() / .zonedDateTimeISO() / .plainDateISO() / .plainTimeISO() (Temporal (Stage 3))
overlapsChecks whether two date ranges overlap.
parseDurationParses a compact duration string (as produced by formatDuration, e.g.
startOfReturns a new `Date` set to the **start** of the given unit.
timeAgoFormats a date as a human-readable relative time string.
toISO8601Converts a date to ISO 8601 format Format: YYYY-MM-DDTHH:mm:ss.sssZ
toMillisConverts a date to a timestamp in **milliseconds** (epoch millis).
toPlainDate / toPlainDateTime / toPlainTimenative JS Temporal.ZonedDateTime.prototype.toPlainDate() / toPlainDateTime() / toPlainTime() (Temporal (Stage 3))
toRFC2822Converts a date to RFC 2822 format Format: Day, DD Mon YYYY HH:mm:ss +0000 Used in email headers (Date field) and HTT…
toRFC3339Converts a date to RFC 3339 format Format: YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss+HH:mm RFC 3339 is a profile of…
toSecondsConverts a date to a timestamp in **seconds** (epoch seconds).
toTemporalInstantnative JS Date.prototype.toTemporalInstant() (Temporal (Stage 3))
toZonedDateTimenative JS Temporal.Instant.prototype.toZonedDateTimeISO(tz) (Temporal (Stage 3))
until / since (difference)native JS Temporal.PlainDate.prototype.until(other) / .since(other) (Temporal (Stage 3))
WeekDaysNamed day-of-week constants following the JavaScript `Date.getDay()` convention.