Generates a random date that can be either in the past or in the future.
Optional
options: { refDate?: string | number | Date }The optional options object.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Generates a random date between the given boundaries.
The options object.
The early date boundary.
The late date boundary.
Generates random dates between the given boundaries. The dates will be returned in an array sorted in chronological order.
The options object.
Optional
count?: number | { max: number; min: number }The number of dates to generate.
The early date boundary.
The late date boundary.
faker.date.betweens({ from: '2020-01-01T00:00:00.000Z', to: '2030-01-01T00:00:00.000Z' })
// [
// '2022-07-02T06:00:00.000Z',
// '2024-12-31T12:00:00.000Z',
// '2027-07-02T18:00:00.000Z'
// ]
faker.date.betweens({ from: '2020-01-01T00:00:00.000Z', to: '2030-01-01T00:00:00.000Z', count: 2 })
// [ '2023-05-02T16:00:00.000Z', '2026-09-01T08:00:00.000Z' ]
faker.date.betweens({ from: '2020-01-01T00:00:00.000Z', to: '2030-01-01T00:00:00.000Z', count: { min: 2, max: 5 }})
// [
// 2021-12-19T06:35:40.191Z,
// 2022-09-10T08:03:51.351Z,
// 2023-04-19T11:41:17.501Z
// ]
Returns a random birthdate. By default, the birthdate is generated for an adult between 18 and 80 years old.
But you can customize the 'age'
range or the 'year'
range to generate a more specific birthdate.
Optional
options: { refDate?: string | number | Date }The options to use to generate the birthdate.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Returns a random birthdate for a given age range.
The options to use to generate the birthdate.
The maximum age to generate a birthdate for.
The minimum age to generate a birthdate for.
'age'
to generate a birthdate based on the age range.
It is also possible to generate a birthdate based on a 'year'
range.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Returns a random birthdate in the given range of years.
The options to use to generate the birthdate.
The maximum year to generate a birthdate in.
The minimum year to generate a birthdate in.
'year'
to generate a birthdate based on the year range.
It is also possible to generate a birthdate based on an 'age'
range.
Returns a random birthdate. By default, the birthdate is generated for an adult between 18 and 80 years old.
But you can customize the 'age'
range or the 'year'
range to generate a more specific birthdate.
Optional
options: The options to use to generate the birthdate.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
The maximum age/year to generate a birthdate for/in.
The minimum age/year to generate a birthdate for/in.
Either 'age'
or 'year'
to generate a birthdate based on the age or year range.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Only used when mode
is 'age'
.
Generates a random date in the future.
Optional
options: { refDate?: string | number | Date; years?: number }The optional options object.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Optional
years?: numberThe range of years the date may be in the future.
Returns a random name of a month.
Optional
options: { abbreviated?: boolean; context?: boolean }The optional options to use.
Optional
abbreviated?: booleanWhether to return an abbreviation.
Optional
context?: booleanWhether to return the name of a month in the context of a date.
In the default en
locale this has no effect,
however, in other locales like fr
or ru
, this may affect grammar or capitalization,
for example 'январь'
with { context: false }
and 'января'
with { context: true }
in ru
.
Generates a random date in the past.
Optional
options: { refDate?: string | number | Date; years?: number }The optional options object.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Optional
years?: numberThe range of years the date may be in the past.
Generates a random date in the recent past.
Optional
options: { days?: number; refDate?: string | number | Date }The optional options object.
Optional
days?: numberThe range of days the date may be in the past.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Generates a random date in the near future.
Optional
options: { days?: number; refDate?: string | number | Date }The optional options object.
Optional
days?: numberThe range of days the date may be in the future.
Optional
refDate?: string | number | DateThe date to use as reference point for the newly generated date.
Returns a random IANA time zone name.
The returned time zone is not tied to the current locale.
Returns a random day of the week.
Optional
options: { abbreviated?: boolean; context?: boolean }The optional options to use.
Optional
abbreviated?: booleanWhether to return an abbreviation.
Optional
context?: booleanWhether to return the day of the week in the context of a date.
In the default en
locale this has no effect,
however, in other locales like fr
or ru
, this may affect grammar or capitalization,
for example 'Lundi'
with { context: false }
and 'lundi'
with { context: true }
in fr
.
Module to generate dates.
Overview
To quickly generate a date in the past, use
recent()
(last day) orpast()
(last year). To quickly generate a date in the future, usesoon()
(next day) orfuture()
(next year). For a realistic birthdate for an adult, usebirthdate()
.For more control, any of these methods can be customized with further options, or use
between()
to generate a single date between two dates, orbetweens()
for multiple dates.If you need to generate a date range (start-end), you can do so using either of these two methods:
const start = faker.date.soon(); const end = faker.date.soon({ refDate: start });
const [start, end] = faker.date.betweens({ from, to, count: 2 });
// does not work with tsconfig'snoUncheckedIndexedAccess: true
Dates can be specified as Javascript Date objects, strings or UNIX timestamps. For example to generate a date between 1st January 2000 and now, use:
You can generate random localized month and weekday names using
month()
andweekday()
.These methods have additional concerns about reproducibility, see Reproducible Results.