create random date js code example
Example 1: generate random date in javascript
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
randomDate(new Date(2012, 0, 1), new Date())
Example 2: random dob in javascript
var dob;
var min = 1900;
var max = 2004;
var month = Math.ceil(Math.random() * 12);
var day = Math.ceil(Math.random() * 28);
var year = Math.floor(Math.random() * (max - min) + min);
if(month < 10) {
month = "0" + month;
}
if(day < 10) {
day = "0" + day;
}
dob = month + "/" + day + "/" + year;
return dob;