screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <title>Random Date Generator</title> </head> <body> <h2>Javascript Random Date yyyy-mm-dd</h2> <p>Start Date : 2023-01-01 </p> <p>End Date : 2023-12-31 </p> <button onclick="generateRandomDate()">Generate Random Date</button> <p id="result"></p> <script> // Define start and end date objects var startDate = new Date('2023-01-01'); var endDate = new Date('2023-12-31'); function getRandomDate(startDate, endDate) { var randomTime = startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()); var randomDate = new Date(randomTime); // Formatting the date to 'YYYY-MM-DD' var formattedDate = randomDate.toISOString().split('T')[0]; return formattedDate; } function generateRandomDate() { var randomDate = getRandomDate(startDate, endDate); // Display the random date on the web page var resultContainer = document.getElementById("result"); resultContainer.innerHTML = randomDate; } </script> </body> </html>