random date generator javascript

Solutions on MaxInterview for random date generator javascript by the best coders in the world

showing results for - "random date generator javascript"
Luka
10 Nov 2020
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())
Henry
02 Jun 2016
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
generate random timestamps javascriptjavascript generate random number based on dategenerate random timestamp javascriptcreate random timestamp javascriptjavascript random number dategenerate random dates jsmath random new datejavascript random dategenerate random number using current date and time javascriptrandom number javascript with date nowjs generate random number date nowgenrate random number date jspick at random javascriptrandom time in jsjs random according to datecreate random date jshow to get a random date in javascriptjavascript random set date methodsjavascript create an array of random datesrandom date generator javasccriptget random date javascriptday js get random adterandom date function in javascripthow to assign a random date using jscreate random number date time in javascriptget random date from past year javascriptjavascript get random dateget random date jstypescript random dates in timeframeget random date in jsjnodejs generate random datesrandom date in javascriptgenerate a random date time javascriptrandom date javascriptcreate a variable that holds a random date and time in javascriptgenerate random date in jsrandom timestamp javascriptdate math random 28 29js random datesrandom date javascript source codecreate random date javascriptrandom timestamp generator javascriptgenerating random datetime in angularget random date from last year javascripthow to create a random date in nodejsjs moment random date future dategenerate random date jsjs generate random dategenerate random date javascriptrandom date string javascriptgenerate unique key injavascript with date and randommoment random dateget random date in javascriptgenerate random dates with timestamp javascriptgenerate random number based on date jsjavascript random date timejs pick random dategenrate date random jsrandom javascript date generatorrandom date javascript codejs random dategenerate random date js new datejs generate random value by datehow to create a random date jsmomen js get random dateangular display random data based on daterandom date generator jsrandom date jsjs get random dategenerate 4 random dates javascriptgenerate random date in javascriptget a random date javascriptrandon rate generator jquryrandom date generator javascriptrandom dob in javascriptrandom number js new daterandom date string generator javasccriptrandom date in jsrandom array according to date javascriptcreate random timestamps javascriptjavascript get random from datejs generate random timestamprandom date generator javascript