On This Page
Dates - Date
A calendar date with no time and no zone: a due date, a birthday, a booking night. It is not a moment, so it never shifts when read from another zone. The class is CalendarDate, a Temporal.PlainDate underneath.
Creating
date
date(input);date(year, month, day);date(input, zone);date(input, { zone, loose, dayFirst });Reads '2026-09-06', three numbers, a fields object, a datetime (its date in its zone), a Date (its date in the zone), or a Temporal value. A wall-clock string keeps its day.
A string carrying Z or an offset is an instant whose day depends on the zone, so it refuses unless { loose: true, zone } says which, or datetime(text, zone).date chooses it. A bare number refuses too, since it is a year to one reader and epoch milliseconds to another.
Parameters
| Name | Type | Description |
|---|---|---|
| input | string | object | DateTime | Date | Temporal | '2026-09-06', { year, month, day }, a datetime, a Date, or a Temporal value |
| year, month, day | number | Three numbers, date(2026, 9, 6). The day defaults to 1 |
| zone | string | The zone a Date is read in |
| options | object | { zone, loose, dayFirst }. See Reading Values |
Returns
A CalendarDate, or null under { loose: true } for input that cannot be read.
Usage
date('2026-09-06').toString(); // '2026-09-06'date(2026, 9, 6).toString(); // '2026-09-06'date('2026-09-06T23:30').toString(); // '2026-09-06'date(datetime('2026-09-06T23:30Z').in('Asia/Tokyo')).toString(); // '2026-09-07'date(new Date('2026-09-06T23:30:00Z'), 'Asia/Tokyo').toString(); // '2026-09-07'date('September 6, 2026', { loose: true }).toString(); // '2026-09-06'Example
today
today();today(zone);Today’s date, in the zone or the configured default. Today depends on where you stand.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
A CalendarDate.
Usage
today().format('full'); // 'Monday, September 7, 2026'today('Asia/Tokyo').toString(); // '2026-09-08'Example
tomorrow
tomorrow();tomorrow(zone);Tomorrow’s date, in the zone or the configured default.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
A CalendarDate.
Usage
tomorrow().since(today(), 'days'); // 1Example
yesterday
yesterday();yesterday(zone);Yesterday’s date, in the zone or the configured default.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
A CalendarDate.
Usage
today().since(yesterday(), 'days'); // 1Example
Properties
The parts are real properties, so a value prints them in a console without a click, and text leads them in the configured locale’s common form, so a preview reads as a date. Every property is read-only.
| Name | Type | Description |
|---|---|---|
| text | string | The day in the configured locale’s common form, 'Sep 6, 2026', what format() prints |
| month | number | 1 through 12 |
| day | number | |
| year | number | |
| weekday | number | ISO, 1 for monday through 7 for sunday |
| quarter | number | 1 through 4 |
| dayOfYear | number | |
| weekOfYear | number | ISO week number |
| daysInMonth | number | |
| daysInYear | number |
Usage
const day = date('2026-09-06');
day.text; // 'Sep 6, 2026'day.year; // 2026day.weekday; // 7day.quarter; // 3day.weekOfYear; // 36day.daysInMonth; // 30Example
Moving
plus
date.plus(duration);date.plus(fields);date.plus(phrase);date.plus(count, unit);Adds years, months, weeks or days, staying within the days a month has. A date has no clock, so a clock unit refuses with notADateUnit. Combine with at() first.
Parameters
| Name | Type | Description |
|---|---|---|
| amount | Duration | object | string | number | A duration, a fields object like { weeks: 2 }, a phrase like '1 month', or a count with a unit |
| unit | string | The unit for a count, 'days', 'weeks', 'months', 'years' |
Returns
A new CalendarDate.
Usage
const day = date('2026-09-06');
day.plus(days(30)).toString(); // '2026-10-06'day.plus('1 month').toString(); // '2026-10-06'day.plus(1, 'year').toString(); // '2027-09-06'date('2026-01-31').plus(months(1)).toString(); // '2026-02-28'day.plus(hours(3)); // throws notADateUnitExample
minus
date.minus(duration);date.minus(fields);date.minus(phrase);date.minus(count, unit);Subtracts years, months, weeks or days.
Parameters
| Name | Type | Description |
|---|---|---|
| amount | Duration | object | string | number | A duration, a fields object, a phrase, or a count with a unit |
| unit | string | The unit for a count |
Returns
A new CalendarDate.
Usage
const day = date('2026-09-06');
day.minus(days(7)).toString(); // '2026-08-30'day.minus('2 weeks').toString(); // '2026-08-23'date('2026-03-01').minus(days(1)).toString(); // '2026-02-28'Example
set
date.set(fields);date.set(unit, value);Replaces the year, month or day. A day the month cannot hold refuses with cannotSet.
Parameters
| Name | Type | Description |
|---|---|---|
| fields | object | Singular keys, { day: 1 } |
| unit | string | 'year', 'month' or 'day' |
| value | number | Its new value |
Returns
A new CalendarDate.
Usage
const day = date('2026-09-06');
day.set({ day: 1 }).toString(); // '2026-09-01'day.set('month', 12).toString(); // '2026-12-06'date('2026-02-01').set({ day: 30 }); // throws cannotSetExample
startOf
date.startOf(unit);date.startOf('week', firstDay);The first day of the unit around this date. A week starts on the configured first day, or on firstDay.
Parameters
| Name | Type | Description |
|---|---|---|
| unit | string | 'year', 'quarter', 'month', 'week' |
| firstDay | string | number | The weekday a week starts on, for 'week' |
Returns
A new CalendarDate.
Usage
const sunday = date('2026-09-06');
sunday.startOf('week').toString(); // '2026-08-31'sunday.startOf('week', 'sunday').toString(); // '2026-09-06'sunday.startOf('quarter').toString(); // '2026-07-01'Example
endOf
date.endOf(unit);date.endOf('week', firstDay);The last day of the unit around this date, so endOf('month') is the 28th, 30th or 31st.
Parameters
| Name | Type | Description |
|---|---|---|
| unit | string | 'year', 'quarter', 'month', 'week' |
| firstDay | string | number | The weekday a week starts on, for 'week' |
Returns
A new CalendarDate.
Usage
const sunday = date('2026-09-06');
sunday.endOf('week').toString(); // '2026-09-06'sunday.endOf('month').toString(); // '2026-09-30'date('2026-02-10').endOf('month').toString(); // '2026-02-28'Example
next
date.next(weekday);The next such weekday strictly after this date.
Parameters
| Name | Type | Description |
|---|---|---|
| weekday | string | number | A name in any spelling, 'monday', 'Fri', or the ISO number |
Returns
A new CalendarDate.
Usage
const sunday = date('2026-09-06');
sunday.next('monday').toString(); // '2026-09-07'sunday.next('sunday').toString(); // '2026-09-13'Example
previous
date.previous(weekday);The previous such weekday strictly before this date.
Parameters
| Name | Type | Description |
|---|---|---|
| weekday | string | number | A name in any spelling, or the ISO number |
Returns
A new CalendarDate.
Usage
const sunday = date('2026-09-06');
sunday.previous('friday').toString(); // '2026-09-04'sunday.previous('sunday').toString(); // '2026-08-30'Example
Comparing
Every comparison takes anything date() reads.
equals
date.equals(other);The same calendar day.
Parameters
| Name | Type | Description |
|---|---|---|
| other | CalendarDate | string | object | Anything date() reads |
Returns
true or false.
Usage
const day = date('2026-09-06');
day.equals('2026-09-06'); // trueday.equals(date(2026, 9, 6)); // trueday.equals('2026-09-07'); // falseExample
isBefore
date.isBefore(other);Whether this date comes before another.
Parameters
| Name | Type | Description |
|---|---|---|
| other | CalendarDate | string | object | Anything date() reads |
Returns
true or false.
Usage
date('2026-09-06').isBefore('2026-09-07'); // truedate('2026-09-06').isBefore('2026-09-06'); // falseExample
isAfter
date.isAfter(other);Whether this date comes after another.
Parameters
| Name | Type | Description |
|---|---|---|
| other | CalendarDate | string | object | Anything date() reads |
Returns
true or false.
Usage
date('2026-09-06').isAfter('2026-09-05'); // truedate('2026-09-06').isAfter(date('2027-01-01')); // falseExample
isSame
date.isSame(other);date.isSame(other, unit);date.isSame(other, 'week', firstDay);Whether two dates share a unit. Without a unit it is equals().
Parameters
| Name | Type | Description |
|---|---|---|
| other | CalendarDate | string | object | Anything date() reads |
| unit | string | 'year', 'quarter', 'month', 'week' |
| firstDay | string | number | The weekday a week starts on, for 'week' |
Returns
true or false.
Usage
const day = date('2026-09-06');
day.isSame('2026-09-30', 'month'); // trueday.isSame('2026-10-01', 'month'); // falseday.isSame('2026-09-01', 'week'); // trueday.isSame('2026-09-01', 'week', 'sunday'); // falseExample
isPast
date.isPast();date.isPast(zone);Whether this date is before today. Today depends on where you stand, so the zone to judge from may be given.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
true or false.
Usage
yesterday().isPast(); // truetomorrow().isPast(); // falseExample
isFuture
date.isFuture();date.isFuture(zone);Whether this date is after today.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
true or false.
Usage
tomorrow().isFuture(); // truetomorrow('UTC').isFuture('UTC'); // trueExample
isToday
date.isToday();date.isToday(zone);Whether this date is today.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
true or false.
Usage
today().isToday(); // truetoday('Asia/Tokyo').isToday('Asia/Tokyo'); // trueExample
isTomorrow
date.isTomorrow();date.isTomorrow(zone);Whether this date is tomorrow.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
true or false.
Usage
tomorrow().isTomorrow(); // trueExample
isYesterday
date.isYesterday();date.isYesterday(zone);Whether this date is yesterday.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose today counts |
Returns
true or false.
Usage
yesterday().isYesterday(); // trueExample
isWeekend
date.isWeekend();Whether this date is a saturday or sunday.
Returns
true or false.
Usage
date('2026-09-06').isWeekend(); // truedate('2026-09-07').isWeekend(); // falseExample
isWeekday
date.isWeekday();Whether this date is monday through friday.
Returns
true or false.
Usage
date('2026-09-07').isWeekday(); // truedate('2026-09-12').isWeekday(); // falseExample
isLeapYear
date.isLeapYear();Whether this date falls in a leap year.
Returns
true or false.
Usage
date('2028-02-01').isLeapYear(); // truedate('2026-02-01').isLeapYear(); // falseExample
Measuring
until
date.until(other);date.until(other, unit);The duration from this date to another, balanced from years down, or the whole length as a number in one unit. The duration remembers this date, so its months and years total. See Durations.
Parameters
| Name | Type | Description |
|---|---|---|
| other | CalendarDate | string | object | Anything date() reads |
| unit | string | A unit to total in, 'days', 'weeks', 'months' |
Returns
A Duration, or a number with a unit. Negative when other comes first.
Usage
const start = date('2026-01-01');
start.until('2027-04-05').toString(); // 'P1Y3M4D'start.until('2027-04-05').format(); // '1 year, 3 months, 4 days'start.until('2027-04-05', 'days'); // 459start.until('2026-07-01').total('months'); // 6Example
since
date.since(other);date.since(other, unit);The duration from another date to this one, other.until(this).
Parameters
| Name | Type | Description |
|---|---|---|
| other | CalendarDate | string | object | Anything date() reads |
| unit | string | A unit to total in |
Returns
A Duration, or a number with a unit.
Usage
date('2027-04-05').since('2026-01-01').toString(); // 'P1Y3M4D'date('2027-04-05').since('2026-01-01', 'days'); // 459Example
Combining
at
date.at(time, zone);date.at(time);date.at();This date at a time of day in a zone, the moment an appointment happens. No time means midnight, no zone means the configured default.
Parameters
| Name | Type | Description |
|---|---|---|
| time | string | Time | object | Anything time() reads, '9:30am', '17:00'. Default midnight |
| zone | string | The zone the wall clock is in. Default the configured zone |
Returns
A DateTime.
Usage
const visit = date('2026-11-03').at('9:30am', 'America/Los_Angeles');
visit.toString(); // '2026-11-03T17:30:00.000Z'visit.zone; // 'America/Los_Angeles'date('2026-11-03').at(time('17:00'), 'UTC').toString(); // '2026-11-03T17:00:00.000Z'date('2026-11-03').at().hour; // 0Example
to
date.to(end);date.to(duration);date.to(count, unit);A range from this date through another, or covering a length, the last day included. See Range Bounds.
Parameters
| Name | Type | Description |
|---|---|---|
| end | CalendarDate | string | object | Duration | Another date, or a length as a duration, fields or phrase |
| count | number | A count with a unit |
| unit | string | The unit for a count |
Returns
A DateRange.
Usage
const start = date('2026-09-01');
start.to('2026-09-07').toString(); // '2026-09-01/2026-09-07'start.to(days(7)).toString(); // '2026-09-01/2026-09-07'start.to(42, 'days').toString(); // '2026-09-01/2026-10-12'start.to(days(7)).contains('2026-09-07'); // trueExample
range
date.range(unit);date.range('week', firstDay);Every day of the unit containing this date, first through last.
Parameters
| Name | Type | Description |
|---|---|---|
| unit | string | 'year', 'quarter', 'month', 'week' |
| firstDay | string | number | The weekday a week starts on, for 'week' |
Returns
A DateRange.
Usage
const day = date('2026-09-15');
day.range('month').toString(); // '2026-09-01/2026-09-30'day.range('week').toString(); // '2026-09-14/2026-09-20'day.range('week', 'sunday').toString(); // '2026-09-13/2026-09-19'Example
points
date.points(step);date.points(step, zone);date.points(count, unit, zone);The day’s points by a step, as datetimes in the zone. today().points('hour') is the day’s hours, today().points(minutes(30)) its half hours.
Parameters
| Name | Type | Description |
|---|---|---|
| step | string | Duration | object | A unit name or a length |
| count | number | A count with a unit |
| unit | string | The unit for a count |
| zone | string | The zone whose midnight starts the day. Default the configured zone |
Returns
An array of DateTime.
Usage
const day = date('2026-09-07');
day.points('hour').length; // 24day.points(minutes(30)).length; // 48day.points(6, 'hours', 'UTC').map(String); // ['2026-09-07T00:00:00.000Z', '2026-09-07T06:00:00.000Z', ...]day.points('hour', 'Europe/Berlin')[0].toString(); // '2026-09-06T22:00:00.000Z'Example
split
date.split(step);date.split(step, zone);date.split(count, unit, zone);The day cut into ranges by a step, as datetime ranges in the zone. A day across a daylight saving change has 23 or 25 hour slots.
Parameters
| Name | Type | Description |
|---|---|---|
| step | string | Duration | object | A unit name or a length |
| count | number | A count with a unit |
| unit | string | The unit for a count |
| zone | string | The zone whose midnight starts the day. Default the configured zone |
Returns
An array of DateTimeRange.
Usage
const day = date('2026-09-07');
day.split('hour').length; // 24day.split(8, 'hours', 'UTC').map(String); // ['2026-09-07T00:00:00.000Z/2026-09-07T08:00:00.000Z', ...]date('2026-03-08').split('hour', 'America/New_York').length; // 23Example
Formatting
format
date.format();date.format(preset);date.format(options);date.format(tokens);date.format(spec, locale);Prints in the configured locale or one given. A date has no clock, so a clock token refuses with noField.
Parameters
| Name | Type | Description |
|---|---|---|
| spec | string | object | A preset, an Intl.DateTimeFormat options object, or a day.js token pattern. See the datetime tokens |
| locale | string | A BCP 47 tag for this call |
Presets
| Preset | Prints |
|---|---|
'short' |
9/6/26 |
'medium' |
Sep 6, 2026, the default |
'long' |
September 6, 2026 |
'full' |
Sunday, September 6, 2026 |
'month' |
September 2026 |
Returns
A string.
Usage
const day = date('2026-09-06');
day.format(); // 'Sep 6, 2026'day.format('full'); // 'Sunday, September 6, 2026'day.format('month'); // 'September 2026'day.format({ weekday: 'long', month: 'long', day: 'numeric' }); // 'Sunday, September 6'day.format('MMMM Do, YYYY'); // 'September 6th, 2026'day.format('ddd D MMM', 'fr'); // 'dim. 6 sept.'day.format('HH:mm'); // throws noFieldExample
formatRelative
date.formatRelative();date.formatRelative(to);date.formatRelative(to, locale);The distance in words, 'yesterday', 'in 3 weeks', 'last month', measured against today unless another date is given.
Parameters
| Name | Type | Description |
|---|---|---|
| to | CalendarDate | string | object | The date to measure against, default today |
| locale | string | A BCP 47 tag for this call |
Returns
A string.
Usage
const reference = date('2026-09-07');
date('2026-09-06').formatRelative(reference); // 'yesterday'date('2026-09-21').formatRelative(reference); // 'in 2 weeks'date('2020-01-01').formatRelative(reference); // '7 years ago'date('2026-09-21').formatRelative(reference, 'de'); // 'in 2 Wochen'Example
Converting
toString
date.toString();ISO 8601, '2026-09-06'. A date is not a number, so < refuses with notANumber rather than being silently wrong.
Returns
A string.
Usage
date('2026-09-06').toString(); // '2026-09-06'`Due ${date('2026-09-06')}`; // 'Due 2026-09-06'date('2026-09-06') < date('2026-09-07'); // throws notANumberExample
toJSON
date.toJSON();The wire form, the ISO day, which date() reads back exactly.
Returns
A string.
Usage
JSON.stringify({ on: date('2026-09-06') }); // '{"on":"2026-09-06"}'Example
toJSDate
date.toJSDate();date.toJSDate(zone);Midnight of this date in the zone, as a JavaScript Date.
Parameters
| Name | Type | Description |
|---|---|---|
| zone | string | The zone whose midnight. Default the configured zone |
Returns
A Date.
Usage
date('2026-11-03').toJSDate('UTC').toISOString(); // '2026-11-03T00:00:00.000Z'date('2026-11-03').toJSDate('America/Los_Angeles').toISOString(); // '2026-11-03T08:00:00.000Z'Example
toTemporal
date.toTemporal();The Temporal.PlainDate underneath.
Returns
A Temporal.PlainDate.
Usage
date('2026-09-06').toTemporal().dayOfWeek; // 7Example
valueOf
date.valueOf();Throws notANumber. A date is not a point on the number line, so due < today() refuses rather than being silently always true. Compare with isBefore(), isAfter() or equals(), or measure with until().