Skip to Content
๐ŸŽฒ Welcome to RandBox - Powerful JavaScript Random Data Generation Library! Learn More

birthday

// usage randBox.birthday() randBox.birthday({ string: true }) randBox.birthday({ type: 'child' })

Generate a random birthday

randBox.birthday(); => Fri Aug 16 1985 00:00:00 GMT-0400 (EDT)

By default, returns an actual JavaScript Dateย  object.

Optionally specify it be returned as a string.

randBox.birthday({string: true}); => '4/1/1968'

By default returns in MM/DD/YYYY format. Can specify DD/MM/YYYY as follows:

randBox.birthday({string: true, american: false}); => '28/6/1993'

For more complex date formats, use the Momentย  library.

Can specify the type, same types as with age.

randBox.birthday({type: 'child'}); => Sat Sep 08 2001 00:00:00 GMT-0400 (EDT)

You can compose with randBox.year for interesting combinations. For example, letโ€™s say we want to get the birthdays of some renaissance artists (born between 1450 and 1500). We can generate a year and then get a birthday from that year:

var year = randBox.year({ min: 1450, max: 1500 }); randBox.birthday({ year: year }); => Wed Aug 27 1484 11:24:14 GMT-0400 (EDT) // Could be simplified down to one line randBox.birthday({ year: randBox.year({ min: 1450, max: 1500 }) }); => Fri Nov 26 1469 09:17:13 GMT-0500 (EST)

Can specify maxAge and/or minAge. This will return a date which yields to an age between the given range. Attention on limits: the full day of birthdays are considered to be part of the allowed range (from the first millisecond of the minimum date to the last second of the maximum date).

randBox.birthday({minAge: 18, maxAge: 21}); => Thu Apr 18 2002 13:48:34 GMT-0400 (EDT)
Last updated on: