How To Get Range Between Two Dates In Javascript?


Share:
Published By: Admin, Published On: Dec 08, 2021, Category: Javascript


Hi Friends,

This Example Is How To Get Range Between Two Dates In Javascript?.

Given two JavaScript `Date` objects, how can I get a list of the days (expressed as Date objects, too) between those 2 dates?.

This is a short code and very easy to explain example.

Now Let's start following step.

Example : 1
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>How To Get Range Between Two Dates In Javascript? - Mywebtuts.com</title>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
	</head>
	<body>
		<script type = "text/javascript">
			// JavaScript program to illustrate 
			// calculation of no. of days between two date 
	  
			// To set two dates to two variables
			var date1 = new Date("06/1/2019");

			var date2 = new Date("06/15/2019");
		  
			// To calculate the time difference of two dates
			var Difference_In_Time = date2.getTime() - date1.getTime();
		  
			// To calculate the no. of days between two dates
			var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24);
		  
			//To display the final no. of days (result)
			document.write(Difference_In_Days+" "+"days");
	  
		</script>
	</body>
</html>
Output :
14 Days
Share: