{"id":1555,"date":"2024-12-04T03:15:35","date_gmt":"2024-12-04T03:15:35","guid":{"rendered":"https:\/\/donhit.com\/en\/?p=1555"},"modified":"2025-02-07T09:35:27","modified_gmt":"2025-02-07T09:35:27","slug":"date-duration","status":"publish","type":"post","link":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/","title":{"rendered":"Date Duration Calculator"},"content":{"rendered":"<p><center>    <div class=\"bg-white shadow-2xl rounded-xl p-8 w-full max-w-md\">\r\n        <h2 class=\"text-2xl font-bold text-center text-blue-600 mb-6 flex items-center justify-center\">\r\n            <i class=\"fas fa-calendar-alt mr-3\"><\/i>\r\n            Date Duration Calculator\r\n        <\/h2>\r\n\r\n        <div class=\"space-y-4\">\r\n            <div>\r\n                <label for=\"start-date\" class=\"block text-sm font-medium text-gray-700 mb-1\">Start Date<\/label>\r\n                <input type=\"date\" id=\"start-date\" class=\"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500\">\r\n            <\/div>\r\n\r\n            <div>\r\n                <label for=\"end-date\" class=\"block text-sm font-medium text-gray-700 mb-1\">End Date<\/label>\r\n                <input type=\"date\" id=\"end-date\" class=\"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500\">\r\n            <\/div>\r\n\r\n            <div class=\"flex space-x-2 items-center\">\r\n                <input type=\"checkbox\" id=\"exclude-weekends\" class=\"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded\">\r\n                <label for=\"exclude-weekends\" class=\"text-sm text-gray-700\">Exclude Weekends<\/label>\r\n            <\/div>\r\n\r\n            <div class=\"flex space-x-2 items-center\">\r\n                <input type=\"checkbox\" id=\"exclude-holidays\" class=\"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded\">\r\n                <label for=\"exclude-holidays\" class=\"text-sm text-gray-700\">Exclude Holidays<\/label>\r\n            <\/div>\r\n\r\n            <button id=\"calculate-btn\" class=\"w-full bg-blue-600 text-white py-2 rounded-md hover:bg-blue-700 transition duration-300 flex items-center justify-center\">\r\n                <i class=\"fas fa-calculator mr-2\"><\/i>\r\n                Calculate Duration\r\n            <\/button>\r\n        <\/div>\r\n\r\n        <div id=\"result\" class=\"mt-6 p-4 bg-blue-50 rounded-md hidden\">\r\n            <h2 class=\"text-lg font-semibold text-blue-700 mb-3\">Result<\/h2>\r\n            <div id=\"result-details\" class=\"space-y-2\"><\/div>\r\n        <\/div>\r\n    <\/div>\r\n\r\n    <script>\r\n        \/\/ Predefined holidays for Vietnam (you can customize this)\r\n        const vietnameseHolidays = [\r\n            '2024-01-01', \/\/ New Year's Day\r\n            '2024-02-10', \/\/ Lunar New Year\r\n            '2024-02-11', \/\/ Lunar New Year\r\n            '2024-02-12', \/\/ Lunar New Year\r\n            '2024-02-13', \/\/ Lunar New Year\r\n            '2024-04-30', \/\/ Liberation Day\r\n            '2024-05-01', \/\/ Labor Day\r\n            '2024-09-02'  \/\/ Independence Day\r\n        ];\r\n\r\n        function isWeekend(date) {\r\n            return date.getDay() === 0 || date.getDay() === 6;\r\n        }\r\n\r\n        function isHoliday(date, holidays) {\r\n            const dateString = date.toISOString().split('T')[0];\r\n            return holidays.includes(dateString);\r\n        }\r\n\r\n        function calculateDuration() {\r\n            const startDateInput = document.getElementById('start-date');\r\n            const endDateInput = document.getElementById('end-date');\r\n            const excludeWeekends = document.getElementById('exclude-weekends').checked;\r\n            const excludeHolidays = document.getElementById('exclude-holidays').checked;\r\n            const resultDiv = document.getElementById('result');\r\n            const resultDetailsDiv = document.getElementById('result-details');\r\n\r\n            \/\/ Reset previous results\r\n            resultDetailsDiv.innerHTML = '';\r\n            resultDiv.classList.add('hidden');\r\n\r\n            \/\/ Validate inputs\r\n            if (!startDateInput.value || !endDateInput.value) {\r\n                alert('Please select both start and end dates');\r\n                return;\r\n            }\r\n\r\n            const startDate = new Date(startDateInput.value);\r\n            const endDate = new Date(endDateInput.value);\r\n\r\n            if (startDate > endDate) {\r\n                alert('Start date must be before end date');\r\n                return;\r\n            }\r\n\r\n            let currentDate = new Date(startDate);\r\n            let totalDays = 0;\r\n            let workingDays = 0;\r\n            let weekends = 0;\r\n            let holidays = 0;\r\n\r\n            \/\/ Calculate differences\r\n            while (currentDate <= endDate) {\r\n                totalDays++;\r\n\r\n                if (excludeWeekends && isWeekend(currentDate)) {\r\n                    weekends++;\r\n                } \r\n                \r\n                if (excludeHolidays && isHoliday(currentDate, vietnameseHolidays)) {\r\n                    holidays++;\r\n                }\r\n\r\n                if (!(excludeWeekends && isWeekend(currentDate)) && \r\n                    !(excludeHolidays && isHoliday(currentDate, vietnameseHolidays))) {\r\n                    workingDays++;\r\n                }\r\n\r\n                currentDate.setDate(currentDate.getDate() + 1);\r\n            }\r\n\r\n            \/\/ Display results\r\n            resultDiv.classList.remove('hidden');\r\n            resultDetailsDiv.innerHTML = `\r\n                <p><strong>Total Days:<\/strong> ${totalDays}<\/p>\r\n                <p><strong>Working Days:<\/strong> ${workingDays}<\/p>\r\n                ${excludeWeekends ? `<p><strong>Weekends Excluded:<\/strong> ${weekends}<\/p>` : ''}\r\n                ${excludeHolidays ? `<p><strong>Holidays Excluded:<\/strong> ${holidays}<\/p>` : ''}\r\n            `;\r\n        }\r\n\r\n        \/\/ Add event listeners\r\n        document.getElementById('calculate-btn').addEventListener('click', calculateDuration);\r\n        \r\n        \/\/ Set default dates\r\n        const today = new Date();\r\n        const endDate = new Date(today);\r\n        endDate.setDate(today.getDate() + 30);\r\n\r\n        document.getElementById('start-date').valueAsDate = today;\r\n        document.getElementById('end-date').valueAsDate = endDate;\r\n    <\/script><\/center><\/p>\n<p style=\"text-align: right;\">\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[185],"tags":[],"class_list":["post-1555","post","type-post","status-publish","format-standard","hentry","category-time-calculators"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Date Duration Calculator - DonHit<\/title>\n<meta name=\"description\" content=\"A date duration calculator is a tool designed to measure the time span between two specific dates. Detail at here\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Date Duration Calculator - DonHit\" \/>\n<meta property=\"og:description\" content=\"A date duration calculator is a tool designed to measure the time span between two specific dates. Detail at here\" \/>\n<meta property=\"og:url\" content=\"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/\" \/>\n<meta property=\"og:site_name\" content=\"DonHit - World of Tools\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-04T03:15:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-07T09:35:27+00:00\" \/>\n<meta name=\"author\" content=\"DonHit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DonHit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Date Duration Calculator - DonHit","description":"A date duration calculator is a tool designed to measure the time span between two specific dates. Detail at here","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/","og_locale":"en_US","og_type":"article","og_title":"Date Duration Calculator - DonHit","og_description":"A date duration calculator is a tool designed to measure the time span between two specific dates. Detail at here","og_url":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/","og_site_name":"DonHit - World of Tools","article_published_time":"2024-12-04T03:15:35+00:00","article_modified_time":"2025-02-07T09:35:27+00:00","author":"DonHit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"DonHit","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/#article","isPartOf":{"@id":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/"},"author":{"name":"DonHit","@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"headline":"Date Duration Calculator","datePublished":"2024-12-04T03:15:35+00:00","dateModified":"2025-02-07T09:35:27+00:00","mainEntityOfPage":{"@id":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/"},"wordCount":9,"commentCount":0,"publisher":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"articleSection":["Time Calculators"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/donhit.com\/en\/time-calculators\/date-duration\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/","url":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/","name":"Date Duration Calculator - DonHit","isPartOf":{"@id":"https:\/\/donhit.com\/en\/#website"},"datePublished":"2024-12-04T03:15:35+00:00","dateModified":"2025-02-07T09:35:27+00:00","description":"A date duration calculator is a tool designed to measure the time span between two specific dates. Detail at here","breadcrumb":{"@id":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/donhit.com\/en\/time-calculators\/date-duration\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/donhit.com\/en\/time-calculators\/date-duration\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Trang ch\u1ee7","item":"https:\/\/donhit.com\/en\/"},{"@type":"ListItem","position":2,"name":"Time Calculators","item":"https:\/\/donhit.com\/en\/category\/time-calculators\/"},{"@type":"ListItem","position":3,"name":"Date Duration Calculator"}]},{"@type":"WebSite","@id":"https:\/\/donhit.com\/en\/#website","url":"https:\/\/donhit.com\/en\/","name":"DonHit - World of tools","description":"","publisher":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/donhit.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148","name":"DonHit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/donhit.com\/en\/wp-content\/uploads\/2024\/11\/logo-donhit.webp","contentUrl":"https:\/\/donhit.com\/en\/wp-content\/uploads\/2024\/11\/logo-donhit.webp","width":400,"height":267,"caption":"DonHit"},"logo":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/image\/"},"description":"DonHit is a website designed to provide useful tools for everyone. Its primary goal is to support and empower the community. All the tools available on the site are completely free to use.","sameAs":["https:\/\/donhit.com\/en"],"url":"https:\/\/donhit.com\/en\/author\/admin_don\/"}]}},"_links":{"self":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/comments?post=1555"}],"version-history":[{"count":2,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1555\/revisions"}],"predecessor-version":[{"id":2213,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1555\/revisions\/2213"}],"wp:attachment":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/media?parent=1555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/categories?post=1555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/tags?post=1555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}