showing results for - "random dob in javascript"
Alice
28 Aug 2017
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())
Giacomo
27 Apr 2020
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;
queries leading to this page
how to get a random date in javascriptjs generate random timestampjs moment random date future dategenerate random date javascriptget random date from last year javascriptrandom array according to date javascriptrandom timestamp javascriptcreate random date javascriptgenerate random date js new datecreate random timestamps javascriptgenrate date random jsrandom number js new daterandom date javascript codejs generate random daterandom date generator javasccriptrandom date jsgenrate random number date jsjavascript random number dategenerate random number based on date jsjavascript generate random number based on datejs get random daterandon rate generator jquryget random date javascriptget random date in jsjday js get random adtejs generate random number date nowrandom date javascript source coderandom javascript date generatorrandom date string generator javasccriptgenerate random date jsjs pick random dategenerate unique key injavascript with date and randomrandom date string javascriptget random date jsjavascript random datehow to assign a random date using jsrandom dob in javascriptrandom date javascriptdate random in javascriptgenerate random timestamps javascriptrandom number javascript with date nowjs random according to dategenerate random timestamp javascriptpick at random javascriptjavascript get random from daterandom timestamp generator javascriptcreate random timestamp javascriptgenerate a random date time javascriptmomen js get random datehow to create a random date in nodejsmoment random daterandom time in jsrandom date in javascriptget a random date javascriptcreate random date jsget random date from past year javascripttake random date jsjs random datetypescript random dates in timeframedate math random 28 29nodejs generate random dateshow to get random date in javascriptrandom date in jsjavascript random date timechoose random jsjavascript random set date methodsgenerate random date in jsangular display random data based on datehow to create a random date jsrandom date generator javascriptgenerate random dates with timestamp javascripthow to manually put in a random date in new date javascriptgenerate random dates jsjs random datesgenerating random datetime in angularrandom date generator jsmath random new datecreate a variable that holds a random date and time in javascriptjavascript get random datejs generate random value by datecreate random number date time in javascriptrandom date function in javascriptjavascript create an array of random dateshow to find random number with date in javascriptnew date random date javascriptgenerate 4 random dates javascriptgenerate random date in javascriptget random date in javascriptgenerate random number using current date and time javascriptrandom dob in javascript