{"id":1230,"date":"2024-12-31T17:15:11","date_gmt":"2024-12-31T11:15:11","guid":{"rendered":"https:\/\/ashrafimahbub.com\/?p=1230"},"modified":"2024-12-31T17:28:45","modified_gmt":"2024-12-31T11:28:45","slug":"advance-retirement-date-calculator","status":"publish","type":"post","link":"https:\/\/ashrafimahbub.com\/?p=1230","title":{"rendered":"Advance Retirement Date Calculator"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Batch Retirement Date Calculator<\/title>\n    <style>\n        .retirement-calculator {\n            font-family: Arial, sans-serif;\n            max-width: 600px;\n            margin: 20px auto;\n            padding: 20px;\n            border: 1px solid #ccc;\n            border-radius: 8px;\n            background-color: #f9f9f9;\n            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n        }\n        .retirement-calculator h2 {\n            text-align: center;\n            margin-bottom: 20px;\n        }\n        .retirement-calculator label {\n            display: block;\n            margin-bottom: 8px;\n            font-weight: bold;\n        }\n        .retirement-calculator input {\n            width: calc(100% - 20px);\n            padding: 8px;\n            margin-bottom: 15px;\n            border: 1px solid #ccc;\n            border-radius: 4px;\n        }\n        .retirement-calculator button {\n            width: 100%;\n            padding: 10px;\n            background-color: #0073aa;\n            color: #fff;\n            border: none;\n            border-radius: 4px;\n            cursor: pointer;\n            margin-bottom: 10px;\n        }\n        .retirement-calculator button:hover {\n            background-color: #005a8c;\n        }\n        .retirement-calculator .result {\n            margin-top: 20px;\n            text-align: center;\n            font-size: 1em;\n            color: #333;\n        }\n        .retirement-calculator table {\n            width: 100%;\n            border-collapse: collapse;\n            margin-top: 20px;\n        }\n        .retirement-calculator table th, .retirement-calculator table td {\n            border: 1px solid #ddd;\n            padding: 8px;\n            text-align: left;\n        }\n        .retirement-calculator table th {\n            background-color: #f4f4f4;\n        }\n    <\/style>\n<\/head>\n<body>\n    <div class=\"retirement-calculator\">\n        <h2>Batch Retirement Date Calculator<\/h2>\n        <label for=\"retirement-age\">Retirement Age:<\/label>\n        <input type=\"number\" id=\"retirement-age\" name=\"retirement-age\" min=\"1\" max=\"120\" placeholder=\"e.g., 65\">\n\n        <label for=\"file-upload\">Upload Excel File:<\/label>\n        <input type=\"file\" id=\"file-upload\" accept=\".xlsx\">\n\n        <button onclick=\"previewFile()\">Preview Data<\/button>\n        <button onclick=\"calculateRetirementDates()\">Calculate Retirement Dates<\/button>\n        <button onclick=\"exportResults()\">Export to Excel<\/button>\n\n        <div class=\"result\" id=\"result\"><\/div>\n        <div id=\"preview\"><\/div>\n    <\/div>\n\n    <script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/xlsx\/0.18.5\/xlsx.full.min.js\"><\/script>\n    <script>\n        let uploadedData = [];\n        let calculatedData = [];\n\n        function previewFile() {\n            const fileInput = document.getElementById('file-upload');\n            const resultDiv = document.getElementById('result');\n            const previewDiv = document.getElementById('preview');\n\n            if (!fileInput.files.length) {\n                resultDiv.textContent = \"Please upload an Excel file.\";\n                return;\n            }\n\n            const file = fileInput.files[0];\n            const reader = new FileReader();\n\n            reader.onload = function (e) {\n                const data = new Uint8Array(e.target.result);\n                const workbook = XLSX.read(data, { type: 'array' });\n                const sheetName = workbook.SheetNames[0];\n                const sheet = workbook.Sheets[sheetName];\n                uploadedData = XLSX.utils.sheet_to_json(sheet, { header: 1 });\n\n                if (uploadedData.length > 1) {\n                    let tableHtml = \"<table><thead><tr><th>Employee ID<\/th><th>Date of Birth<\/th><\/tr><\/thead><tbody>\";\n                    uploadedData.slice(1).forEach(row => {\n                        const dob = formatDate(row[1]);\n                        tableHtml += `<tr><td>${row[0] || \"\"}<\/td><td>${dob || \"Invalid Date\"}<\/td><\/tr>`;\n                    });\n                    tableHtml += \"<\/tbody><\/table>\";\n                    previewDiv.innerHTML = tableHtml;\n                } else {\n                    previewDiv.innerHTML = \"No data found in the uploaded file.\";\n                }\n            };\n\n            reader.readAsArrayBuffer(file);\n        }\n\n        function calculateRetirementDates() {\n            const retirementAgeInput = document.getElementById('retirement-age').value;\n            const resultDiv = document.getElementById('result');\n            const previewDiv = document.getElementById('preview');\n\n            if (!uploadedData.length) {\n                resultDiv.textContent = \"Please upload and preview an Excel file first.\";\n                return;\n            }\n\n            const retirementAge = parseInt(retirementAgeInput, 10);\n\n            if (isNaN(retirementAge) || retirementAge <= 0) {\n                resultDiv.textContent = \"Please enter a valid retirement age.\";\n                return;\n            }\n\n            calculatedData = uploadedData.slice(1).map(row => {\n                const employeeId = row[0];\n                const dobRaw = row[1];\n                let dob = parseExcelDate(dobRaw);\n\n                if (!dob || isNaN(dob)) {\n                    return {\n                        'Employee ID': employeeId || \"\",\n                        'Date of Birth': dobRaw || \"\",\n                        'Retirement Date': 'Invalid Date'\n                    };\n                }\n\n                const retirementDate = new Date(dob.getFullYear() + retirementAge, dob.getMonth(), dob.getDate());\n                return {\n                    'Employee ID': employeeId || \"\",\n                    'Date of Birth': dob.toLocaleDateString('en-AU', { year: 'numeric', month: 'long', day: 'numeric' }),\n                    'Retirement Date': retirementDate.toLocaleDateString('en-AU', { year: 'numeric', month: 'long', day: 'numeric' })\n                };\n            });\n\n            let resultHtml = \"<table><thead><tr><th>Employee ID<\/th><th>Date of Birth<\/th><th>Retirement Date<\/th><\/tr><\/thead><tbody>\";\n            calculatedData.forEach(row => {\n                resultHtml += `<tr><td>${row['Employee ID']}<\/td><td>${row['Date of Birth']}<\/td><td>${row['Retirement Date']}<\/td><\/tr>`;\n            });\n            resultHtml += \"<\/tbody><\/table>\";\n            previewDiv.innerHTML = resultHtml;\n\n            resultDiv.textContent = \"Retirement dates calculated successfully.\";\n        }\n\n        function exportResults() {\n            if (!calculatedData.length) {\n                alert(\"Please calculate retirement dates before exporting.\");\n                return;\n            }\n\n            const ws = XLSX.utils.json_to_sheet(calculatedData);\n            const wb = XLSX.utils.book_new();\n            XLSX.utils.book_append_sheet(wb, ws, \"Retirement Dates\");\n            XLSX.writeFile(wb, \"Retirement_Dates.xlsx\");\n        }\n\n        function parseExcelDate(excelDate) {\n            if (typeof excelDate === 'number') {\n                const date = new Date((excelDate - 25569) * 86400 * 1000);\n                return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());\n            }\n            return new Date(excelDate);\n        }\n\n        function formatDate(date) {\n            const parsedDate = parseExcelDate(date);\n            return isNaN(parsedDate) ? null : parsedDate.toLocaleDateString('en-AU', { day: '2-digit', month: 'long', year: 'numeric' });\n        }\n    <\/script>\n<\/body>\n<\/html>\n\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>If you want to calculate only one date <a href=\"https:\/\/ashrafimahbub.com\/?p=1226\">CLICK HERE<\/a><\/p>\n<div class=\"fb-background-color\">\n\t\t\t  <div \n\t\t\t  \tclass = \"fb-comments\" \n\t\t\t  \tdata-href = \"https:\/\/ashrafimahbub.com\/?p=1230\"\n\t\t\t  \tdata-numposts = \"10\"\n\t\t\t  \tdata-lazy = \"true\"\n\t\t\t\tdata-colorscheme = \"light\"\n\t\t\t\tdata-order-by = \"social\"\n\t\t\t\tdata-mobile=true>\n\t\t\t  <\/div><\/div>\n\t\t  <style>\n\t\t    .fb-background-color {\n\t\t\t\tbackground: #ffffff !important;\n\t\t\t}\n\t\t\t.fb_iframe_widget_fluid_desktop iframe {\n\t\t\t    width: 320px !important;\n\t\t\t}\n\t\t  <\/style>\n\t\t  ","protected":false},"excerpt":{"rendered":"<p>Batch Retirement Date Calculator Batch Retirement Date Calculator Retirement Age: Upload Excel File: Preview Data Calculate Retirement Dates Export to Excel If you want to calculate only one date CLICK HERE<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,263],"tags":[320,307,306,310,317,308,316,312,314,305,311,315,309,313,319,318],"class_list":["post-1230","post","type-post","status-publish","format-standard","hentry","category-all","category-hr-analytics","tag-advance-retirement-date-calculator","tag-calculate-service-length","tag-employee-calculator","tag-employee-excel-data","tag-employee-management-tool","tag-employee-service-length","tag-employee-service-tracking","tag-excel-date-conversion","tag-export-service-length-to-excel","tag-html-service-calculator","tag-joining-date-calculation","tag-service-length-calculation-tool","tag-service-length-export","tag-wordpress-custom-html","tag-wordpress-employee-tool","tag-wordpress-table-script"],"_links":{"self":[{"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=\/wp\/v2\/posts\/1230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1230"}],"version-history":[{"count":6,"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=\/wp\/v2\/posts\/1230\/revisions"}],"predecessor-version":[{"id":1236,"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=\/wp\/v2\/posts\/1230\/revisions\/1236"}],"wp:attachment":[{"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ashrafimahbub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}