<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Date Comparison</title>
font-family: Arial, sans-serif;
<h2>Date Comparison with Current Date in Javascript</h2>
<p>Current Date: <span id="currentDate"></span></p>
<p>Selected Date: <span id="selectedDate">2025-01-01</span></p>
<button onclick="compareWithCurrentDate()">Compare with Current Date</button>
function compareWithCurrentDate() {
const currentDateElement = document.getElementById('currentDate');
const selectedDateElement = document.getElementById('selectedDate');
const resultElement = document.getElementById('result');
const selectedDate = new Date(selectedDateElement.textContent);
const currentDate = new Date();
currentDateElement.textContent = currentDate.toDateString();
if (selectedDate < currentDate) {
resultMessage = 'Selected date is in the past';
} else if (selectedDate > currentDate) {
resultMessage = 'Selected date is in the future';
resultMessage = 'Selected date is today';
resultElement.textContent = resultMessage;
// Call the function to display the current date initially
compareWithCurrentDate();