I'm trying to use the community fakerjs library to get a random birthdate. I want it to be within the last 70 years at the latest. In my output, though, I keep getting years like 79 and 12 instead of 1979 or 2012. I can only get a 2-digit year.
let date = faker.date.birthdate({ max: 70, min: 1 });
// 0037-08-27T13:35:09.312Z
date.getFullYear()
// 37
.birthdate() by itself works fine, it's just when I use max and min that the problem shows up.
What am I doing wrong?
There's no bug, I just wasn't reading the docs correctly. I assumed
faker.date.birthdate({ max: 70, min: 1 })would understand70and1to be ages, but the method by default thinks they're actually years, so it's imagining that I want anything between the year0001and the year0070.I needed to add
mode: 'age'to the options:By default,
modeis set toyear.