Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js get random data between two dates

function randomDate(start, end, startHour, endHour) {
  var date = new Date(+start + Math.random() * (end - start));
  var hour = startHour + Math.random() * (endHour - startHour) | 0;
  date.setHours(hour);
  return date;
}

console.log(randomDate(new Date(2020, 0, 1), new Date(), 0, 24));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #random #data #dates
ADD COMMENT
Topic
Name
6+1 =