How to check if one date is between two dates in JavaScript ? Last Updated : 12 Jul, 2025 Suggest changes Share Like Article Like Report The task is to determine if the given date is in between the given 2 dates or not? Here are a few of the most used techniques discussed with the help of JavaScript. In the first approach, we will use .split() method and the new Date() constructor. And in the second approach we will use the .getTime() method with the new Date() constructor. Approach 1: Use .split() method to split the date on "/" to get the day, month and year in an array. The we have to construct the date from the array obtained in previous step for that we will use the new Date() constructor . Because this method returns the number of seconds from 1 Jan 1970, So it becomes easy to compare the dates. Example: This example uses the approach discussed above. html <!DOCTYPE HTML> <html> <head> <title> How to Check if one Date is between two dates using JavaScript ? </title> <style> body { text-align: center; } h1 { color: green; } #geeks { font-weight: bold; } </style> </head> <body> <h1>GeeksforGeeks</h1> <p> Date 1 = "06/04/2019" Date 2 = "07/10/2019" <br>Date_to_check = "02/12/2019" </p> <button onclick="gfg_Run()"> Click Here </button> <p id="geeks"></p> <script> var el_down = document.getElementById("geeks"); // Format - MM/DD/YYYY var Date_1 = "06/04/2019"; var Date_2 = "07/10/2019"; var Date_to_check = "02/12/2019"; function gfg_Run() { D_1 = Date_1.split("/"); D_2 = Date_2.split("/"); D_3 = Date_to_check.split("/"); var d1 = new Date(D_1[2], parseInt(D_1[1]) - 1, D_1[0]); var d2 = new Date(D_2[2], parseInt(D_2[1]) - 1, D_2[0]); var d3 = new Date(D_3[2], parseInt(D_3[1]) - 1, D_3[0]); if (d3 > d1 && d3 < d2) { el_down.innerHTML = "Date is in between the " + "Date 1 and Date 2"; } else { el_down.innerHTML = "Date is not in between " + "the Date 1 and Date 2"; } } </script> </body> </html> Output: Approach 2: Here first use new Date() constructor and pass the string in it which makes a Date Object. The .getTime() method which returns the number of seconds from 1 Jan 1970 and Seconds can be easily compared. Example: This example uses the approach discussed above. html <!DOCTYPE HTML> <html> <head> <title> How to Check if one Date is between two dates using JavaScript ? </title> <style> body { text-align: center; } h1 { color: green; } #geeks { font-weight: bold; } </style> </head> <body> <h1>GeeksforGeeks</h1> <p> Date 1 = "06/04/2019" Date 2 = "07/10/2019" <br>Date_to_check = "02/8/2019" </p> <button onclick="gfg_Run()"> Click Here </button> <p id="geeks"></p> <script> var el_down = document.getElementById("geeks"); // Format - MM/DD/YYYY var D1 = "06/04/2019"; var D2 = "07/10/2019"; var D3 = "02/8/2019"; function gfg_Run() { D1 = new Date(D1); D2 = new Date(D2); D3 = new Date(D3); if (D3.getTime() <= D2.getTime() && D3.getTime() >= D1.getTime()) { el_down.innerHTML = "Date is in between" + " the Date 1 and Date 2"; } else { el_down.innerHTML = "Date is not in" + " between the Date 1 and Date 2"; } } </script> </body> </html> Output: P PranchalKatiyar Follow Article Tags : JavaScript Web Technologies javascript-date JavaScript-Misc Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like