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);
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?
- Why does Date.parse give incorrect results?
- Generating random whole numbers in JavaScript in a specific range?
- Convert a Unix timestamp to time in JavaScript
- Generate random string/characters in JavaScript
- How do I get the current date in JavaScript?
- Generate random number between two numbers in JavaScript
- Random color generator
- How to add number of days to today’s date? [duplicate]
- How do you display JavaScript datetime in 12 hour AM/PM format?
- How do I get the difference between two Dates in JavaScript?
- Seeding the random number generator in Javascript
- How to subtract days from a plain Date?
- JavaScript seconds to time string with format hh:mm:ss
- Comparing date part only without comparing time in JavaScript
- Why does the month argument range from 0 to 11 in JavaScript’s Date constructor?
- Browsers, time zones, Chrome 67 Error (historic timezone changes)
- Calculate last day of month
- Difference in Months between two dates in JavaScript
- How to subtract date/time in JavaScript? [duplicate]
- How to convert date to timestamp?
- How to parse a time into a Date object from user input in JavaScript?
- “Deprecation warning: moment construction falls back to js Date” when trying to convert RFC2822 date in moment.js
- Javascript: how to validate dates in format MM-DD-YYYY?
- Add A Year To Today’s Date
- Javascript format date / time [duplicate]
- How to change the pop-up position of the jQuery DatePicker control
- Sampling a random subset from an array
- Random number generator without dupes in Javascript?
- How to JSON stringify a javascript Date and preserve timezone
- How do I localize the jQuery UI Datepicker?
- Check if one date is between two dates
- How to parse a date in format “YYYYmmdd” in JavaScript?
- Show week number with Javascript?
- Convert string to datetime
- Calculate Timezone offset only for one particular timezone
- JavaScript Detecting Valid Dates
- Javascript date variable assignment
- Javascript equivalent of php’s strtotime()?
- Moment Js UTC to Local Time
- How to split a string at the first `/` (slash) and surround part of it in a “?
- Calculating the difference between two dates
- Why isn’t “2016-02-16” equal to “2016-02-16 00:00”?
- Inserting and Querying Date with MongoDB and Nodejs
- Get today date in Google Apps Script
- Javascript Invalid Date Error in Internet Explorer
- How do I calculate the date in JavaScript three months prior to today?
- How to sort an array of objects by date?