Skip to content

Instantly share code, notes, and snippets.

@ansidev
Created April 22, 2019 09:20
Show Gist options
  • Save ansidev/af5d684f5f3da7890fda9d54f815c750 to your computer and use it in GitHub Desktop.
Save ansidev/af5d684f5f3da7890fda9d54f815c750 to your computer and use it in GitHub Desktop.
Random a date in Javascript
function randomDate(startDate, endDate) {
return new Date(
startDate.getTime() +
Math.random() * (endDate.getTime() - startDate.getTime())
);
}
// Random a date in 2019
console.log(randomDate(new Date(2019, 0, 1), new Date(2019, 11, 31)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment