function calculateDates() {
const today = new Date();
const tbody = document.getElementById(‘dateTableBody’);
// Generate dates starting from 492 days ago
const daysAgo = 492;
const pastDate = new Date();
pastDate.setDate(today.getDate() – daysAgo);
const options = { weekday: ‘long’, year: ‘numeric’, month: ‘long’, day: ‘numeric’ };
const formattedDate = pastDate.toLocaleDateString(‘en-US’, options);
// Display result for 492 days ago
document.getElementById(‘currentDate’).innerHTML = formatToReadableDate(today);
document.getElementById(‘492DaysAgoFromToday’).innerHTML = formattedDate;
document.getElementById(‘dateResult’).innerHTML = `492 Days ago from Today:
${formattedDate}`;
} function calculateDaysAgoFromToday(days) {
const today = new Date();
today.setDate(today.getDate() – days);
return today;
} function formatToReadableDate(date) {
const options = { weekday: ‘long’, year: ‘numeric’, month: ‘short’, day: ‘numeric’ };
return date.toLocaleDateString(‘en-US’, options);
} const today = new Date();
const formattedToday = formatToReadableDate(today);
const daysAgo492FromToday = calculateDaysAgoFromToday(492); document.getElementById(‘currentDate’).innerHTML = formattedToday;
document.getElementById(‘492DaysAgoFromToday’).innerHTML = formatToReadableDate(daysAgo492FromToday); document.getElementById(‘dateResult’).innerHTML = `492 Days ago from Today:
${formatToReadableDate(daysAgo492FromToday)}`; function calculateCustomDate() {
const daysInput = document.getElementById(‘days’).value;
if (daysInput !== ”) {
const customDate = formatToReadableDate(calculateDaysAgoFromToday(parseInt(daysInput)));
const customDateResult = document.getElementById(‘customDateResult’);
customDateResult.innerHTML = `
Date ${daysInput} days ago from today: ${customDate}
`;
customDateResult.style.display = ‘block’;
} else {
document.getElementById(‘customDateResult’).innerHTML = ‘
Please enter a valid number of days.
‘;
}
} function formatDateToDifferentFormats(date) {
const usFormat = date.toLocaleDateString(‘en-US’);
const ukFormat = date.toLocaleDateString(‘en-GB’);
const isoFormat = date.toISOString().split(‘T’)[0];
return { usFormat, ukFormat, isoFormat };
} const { usFormat, ukFormat, isoFormat } = formatDateToDifferentFormats(daysAgo492FromToday);
document.getElementById(‘dateFormats’).innerHTML =
`
🇺🇸 | ${usFormat} |
🇬🇧 | ${ukFormat} |
ISO | ${isoFormat} |
`; function copyResult() {
const resultText = document.querySelector(‘#dateResult strong’).innerText;
const textarea = document.createElement(‘textarea’);
textarea.value = resultText;
document.body.appendChild(textarea);
textarea.select();
document.execCommand(‘copy’);
document.body.removeChild(textarea);
showNotification(‘Copied to clipboard: ‘ + resultText);
} function shareURL() {
const url = window.location.href;
const textarea = document.createElement(‘textarea’);
textarea.value = url;
document.body.appendChild(textarea);
textarea.select();
document.execCommand(‘copy’);
document.body.removeChild(textarea);
showNotification(‘Copied URL to clipboard: ‘ + url);
} function showNotification(message) {
const notificationDiv = document.getElementById(‘notification’);
notificationDiv.innerHTML = `
${message}
`;
notificationDiv.style.display = ‘block’; setTimeout(() => {
notificationDiv.style.display = ‘none’;
}, 3000);
} window.onload = calculateDates;
Days Ago From Today Calculator Table