Maybe I am missing something, but isn’t this it?
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
const d = randomDate(new Date(2012, 0, 1), new Date());
console.log(d);
More Related Contents:
- jQuery UI DatePicker to show month year only
- How do I pre-populate a jQuery Datepicker textbox with today’s date?
- How to add/subtract dates with JavaScript?
- Do not include in random number
- new Date(2015,2,30) and new Date(‘2015-2-30’)
- How do I format a date in JavaScript?
- Getting a random value from a JavaScript array
- Generate random number between two numbers in JavaScript
- Random color generator
- Calculate age given the birth date in the format YYYYMMDD
- How to validate date with format “mm/dd/yyyy” in JavaScript?
- Javascript: how to validate dates in format MM-DD-YYYY?
- How to convert dd/mm/yyyy string into JavaScript Date object?
- Javascript format date / time [duplicate]
- Sampling a random subset from an array
- Is Math.random() cryptographically secure?
- How to Convert any of the 5 Islamic (Hijri) Calendars’ Dates to any of 18 World Calendars without External Libraries or Complex Astronomical Formulas
- Get the weekday from a Date object or date string using JavaScript
- How can I remove time from date with Moment.js?
- JavaScript Detecting Valid Dates
- Stop javascript Date function from changing timezone offset
- Write a truly inclusive random method for javascript
- How to properly add 1 month to current date in moment.js
- How to Convert Persian (Jalali) Dates to other 18 Calendar Dates in Javascript without External Libraries or Complex Astronomical Equations
- Loop through a date range with JavaScript
- Javascript date parsing on Iphone
- create javascript date UTC
- How do I format a Javascript Date?
- Get today date in Google Apps Script
- moment.js isValid function not working properly