Created
May 28, 2017 11:35
-
-
Save theamanbhargava/7bb708989b745e608b4f94c7049aa99c to your computer and use it in GitHub Desktop.
Random Date Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Random Date Generator | |
Generates date in YYYY-MM-DD format | |
Courtesy : Different answers on SO | |
--> | |
//change value of multiplier of Math.random() to get older dates | |
var date = new Date(+(new Date()) - Math.floor(Math.random()*500000000000)); | |
function formatDate(date) { | |
var d = new Date(date), | |
month = '' + (d.getMonth() + 1), | |
day = '' + d.getDate(), | |
year = d.getFullYear(); | |
if (month.length < 2) month = '0' + month; | |
if (day.length < 2) day = '0' + day; | |
return [year, month, day].join('-'); | |
} | |
date = formatDate(date); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment