Answers for "random dob in javascript"

0

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())
Posted by: Guest on October-23-2020
1

random dob in javascript

var dob;

//set a range of years
var min = 1900;
var max = 2004;

// Math.ceil prevents the value from being 0;
var month = Math.ceil(Math.random() * 12);
var day = Math.ceil(Math.random() * 28);
var year = Math.floor(Math.random() * (max - min) + min);

//this ensures that the format will stay mm/dd/yyyy;
if(month < 10) {
	month = "0" + month;
}
if(day < 10) {
	day = "0" + day;
}
//concatenates random dob in mm/dd/yyyy format;
dob = month + "/" + day + "/" + year;

return dob;
Posted by: Guest on November-10-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language