1function randomDate(start, end) {
2 return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
3}
4
5randomDate(new Date(2012, 0, 1), new Date())
1var dob;
2
3//set a range of years
4var min = 1900;
5var max = 2004;
6
7// Math.ceil prevents the value from being 0;
8var month = Math.ceil(Math.random() * 12);
9var day = Math.ceil(Math.random() * 28);
10var year = Math.floor(Math.random() * (max - min) + min);
11
12//this ensures that the format will stay mm/dd/yyyy;
13if(month < 10) {
14 month = "0" + month;
15}
16if(day < 10) {
17 day = "0" + day;
18}
19//concatenates random dob in mm/dd/yyyy format;
20dob = month + "/" + day + "/" + year;
21
22return dob;