UNPKG

1.41 kBMarkdownView Raw
1# birthday
2
3```js
4// usage
5chance.birthday()
6chance.birthday({ string: true })
7chance.birthday({ type: 'child' })
8```
9
10Generate a random birthday
11
12```js
13chance.birthday();
14=> Fri Aug 16 1985 00:00:00 GMT-0400 (EDT)
15```
16
17By default, returns an actual JavaScript [Date][Date] object.
18
19Optionally specify it be returned as a string.
20
21```js
22chance.birthday({string: true});
23=> '4/1/1968'
24```
25
26By default returns in MM/DD/YYYY format. Can specify DD/MM/YYYY as follows:
27
28```js
29chance.birthday({string: true, american: false});
30=> '28/6/1993'
31```
32
33For more complex date formats, use the [Moment][Moment] library.
34
35Can also specify the type, same types as with [age](#age).
36
37```js
38chance.birthday({type: 'child'});
39=> Sat Sep 08 2001 00:00:00 GMT-0400 (EDT)
40```
41
42You can also compose with `chance.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:
43
44```js
45var year = chance.year({ min: 1450, max: 1500 });
46chance.birthday({ year: year });
47=> Wed Aug 27 1484 11:24:14 GMT-0400 (EDT)
48
49// Could be simplified down to one line
50chance.birthday({ year: chance.year({ min: 1450, max: 1500 }) });
51=> Fri Nov 26 1469 09:17:13 GMT-0500 (EST)
52```
53
54[Date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
55[Moment]: http://momentjs.com