Skip to content

Date Helpers

Utility functions for working with date operations.

Function Description
add / subtract (date arithmetic) native JS Temporal.PlainDate.prototype.add(duration) / .subtract(duration) (Temporal (Stage 3))
addDays Adds days to a date.
addMonths Adds months to a date.
addYears Adds years to a date.
clampDate Clamps a date to a [min, max] range.
compare Comparison of two dates.
compare (ordering) native JS Temporal.PlainDate.compare(a, b) / Temporal.Instant.compare(a, b) (Temporal (Stage 3))
daysInMonth Returns the number of days in the given month of the given year.
difference Calculates the difference between two dates in the specified unit.
eachDay Returns an array of `Date` objects for each day from `start` to `end` (inclusive).
eachMonth Returns an array of `Date` objects for the first day of each month from `start` to `end` (inclusive).
endOf Returns a new `Date` set to the **end** of the given unit.
ensureDate Safely converts a date-like value to a valid `Date` object, or returns `null`.
formatDuration Formats a duration in milliseconds as a compact human-readable string.
formatInTimezone Formats 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))
fromMillis Creates a `Date` from a timestamp in **milliseconds**.
fromSeconds Creates a `Date` from a timestamp in **seconds**.
getTimezoneOffset Returns the UTC offset **in minutes** for the given IANA timezone at a specific point in time.
isBusinessDay Checks whether a date falls on a business day (i.e.
isLeapYear Returns `true` if the given year is a leap year.
isSameDay Checks if two dates are the same day.
isSameMonth Checks if two dates are in the same month (and year).
isSameYear Checks if two dates are in the same year.
isTimestampInSeconds Checks if a timestamp is likely in seconds (Java/Unix style) vs milliseconds (JavaScript style)
isValid Checks if a value is a valid Date instance (not `Invalid Date`).
isValidDateString Checks whether a string can be parsed into a valid `Date`.
isWeekend Checks whether a date falls on a weekend day.
isWithinRange Checks whether a date falls within a range (inclusive on both ends).
listTimezones Returns the list of IANA timezone identifiers supported by the runtime.
normalizeTimestamp Converts a timestamp to JavaScript milliseconds format
now (date/time/instant) native JS Temporal.Now.instant() / .zonedDateTimeISO() / .plainDateISO() / .plainTimeISO() (Temporal (Stage 3))
overlaps Checks whether two date ranges overlap.
parseDuration Parses a compact duration string (as produced by formatDuration, e.g.
startOf Returns a new `Date` set to the **start** of the given unit.
timeAgo Formats a date as a human-readable relative time string.
toISO8601 Converts a date to ISO 8601 format Format: YYYY-MM-DDTHH:mm:ss.sssZ
toMillis Converts a date to a timestamp in **milliseconds** (epoch millis).
toPlainDate / toPlainDateTime / toPlainTime native JS Temporal.ZonedDateTime.prototype.toPlainDate() / toPlainDateTime() / toPlainTime() (Temporal (Stage 3))
toRFC2822 Converts a date to RFC 2822 format Format: Day, DD Mon YYYY HH:mm:ss +0000 Used in email headers (Date field) and HTTP …
toRFC3339 Converts 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 I…
toSeconds Converts a date to a timestamp in **seconds** (epoch seconds).
toTemporalInstant native JS Date.prototype.toTemporalInstant() (Temporal (Stage 3))
toZonedDateTime native JS Temporal.Instant.prototype.toZonedDateTimeISO(tz) (Temporal (Stage 3))
until / since (difference) native JS Temporal.PlainDate.prototype.until(other) / .since(other) (Temporal (Stage 3))
WeekDays Named day-of-week constants following the JavaScript `Date.getDay()` convention.