How to use faker.date.between faker.js

I want to generate some dates between two fixed values, but I don't know how to

use faker.date.between to achieve that.

the example in faker js demo is just giving a null value.

2 Answers

Not sure when did they update wiki, but they do have a working sample for date.between now

faker.date.between('2015-01-01', '2015-01-05'); 
1

Their code from Github shows:

self.between = function (from, to) { var fromMilli = Date.parse(from); var dateOffset = faker.random.number(Date.parse(to) - fromMilli); var newDate = new Date(fromMilli + dateOffset); return newDate; }; 

And I don't know how you're using it, or why it's not working on their example.... But this should give you some direction, at least.

If this does not help you, or is still producing an undesired result, I would open an issue up on their github.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like