How to check if one date is between two dates in JavaScript ? Last Updated : 20 Jun, 2022 Comments Improve Suggest changes 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: Comment More infoAdvertise with us Next Article How to check if the given date is weekend ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-date JavaScript-Misc Similar Reads How to get tomorrow's date in a string format in JavaScript ? In this article, we will see how to print tomorrow's date in string representation using JavaScript. To achieve this, we use the Date object and create an instance of it. After that by using the setDate() method, we increase one date to the present date. Now by using the getDate() method you will ge 2 min read How to check for two timestamp for the same day? Given two timestamp then we have to find out whether these time are of same date or not. Here we can use the JavaScript Date Object. Examples: Input: TimeStamp1 = 20-04-2020 , 16:04:55 and TimeStamp2 = 20-04-2020 , 10:22:42 Output: These dates are of same dateInput: TimeStamp1 = 20-04-2020 , 16:04:5 3 min read How to get seconds since epoch in JavaScript? Given a date, we have to find the number of seconds since the epoch (i.e. 1 January 1970, 00:00:00 UTC ). The getTime() method in the JavaScript returns the number of milliseconds since January 1, 1970, or epoch. If we divide these milliseconds by 1000 and then integer part will give us the number o 1 min read How to check if one date is between two dates in JavaScript ? 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( 3 min read How to check if the given date is weekend ? To check if a given date falls on a weekend in JavaScript, you can use the getDay() method on a Date object. This method returns a number representing the day of the week, where 0 is Sunday and 6 is Saturday.There are two methods to solve this problem which are discussed below: Table of ContentUsing 2 min read How to Convert Date to Another Timezone in JavaScript? Converting a date to another timezone in JavaScript means adjusting the local date and time to match the time in a different timezone. This ensures that the displayed time aligns with the selected timezone, often using built-in methods or external libraries.1. Using Intl.DateTimeFormat() and format( 2 min read How to check if date is less than 1 hour ago using JavaScript ? Given a date and the task is to check whether the given date is less than 1 hour ago or not with the help of JavaScript. Approach 1: Count the milliseconds of the difference between the current and prev_date.If those are greater than milliseconds in 1 hour, then it returns false otherwise returns tr 2 min read How to check a date is valid or not using JavaScript? To check if a date is valid or not in JavaScript, we have to know all the valid formats of the date. For ex - "YYYY/DD/MM", "DD/MM/YYYY", and "YYYY-MM-DD", etc. We have a given date format and we need to check whether the given format is valid or not according to the official and acceptable date for 3 min read How to get the day and month of a year using JavaScript ? Given a date and the task is to get the day and month of a year using JavaScript. Approach: First get the current date by using new Date().Use getDay() method to get the current day in number format, Map it to the day name.Use getMonth() to get the current month in number format, Map it to the month 2 min read How to calculate the date three months prior using JavaScript ? To calculate the date three months prior using JavaScript, we could use the getMonth() and setMonth() methods. In this article, we are going to learn how to calculate the date three months prior using JavaScript. ApproachFirst, select the date object.Then use the getMonth() method to get the months. 1 min read Like