How To Check If Date Is Greater Than Another In JavaScript?


Share:
Published By: Admin, Published On: Sep 15, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to check if date is greater than another example. We will use how to check if date is greater than another in javascript. Here you will learn how to use javascript check if date is greater than another. This is a short guide on check if date is greater than another. Let's get started with how to check if date is greater than another in javascript.

Here i will give you many example how you can check if date is greater than another javascript.

Example : 1
<!DOCTYPE html>
<html>
		<head>
				<meta charset="utf-8">
				<title>How To Check If Date is Greater Than Another in JavaScript - MyWebtuts.com ?</title>
		</head>
		<body>
		<script type="text/javascript">
				var emp1 = new Date(2017 - 3 - 4);
				// (YYYY-MM-DD)
				var emp2 = new Date(2015 - 8 - 3);
				if (emp1.getTime() < emp2.getTime())
						document.write("emp1 is lesser than emp2");
				else if (emp1.getTime() > emp2.getTime())
						document.write("emp1 is greater than emp2");
				else
						document.write("both are equal");
		</script>
		</body>
</html>
Output :
emp1 is greater than emp2
Example : 2
<!DOCTYPE html>
<html>
		<head>
				<meta charset="utf-8">
				<title>How To Check If Date is Greater Than Another in JavaScript - MyWebtuts.com ?</title>
		</head>
		<body>
		<script>
				var emp1 = new Date(2019, 8, 3, 11, 45, 55);
				// (YYYY, MM, DD, Hr, Min, Sec)
				var emp2 = new Date(2018, 8, 3, 11, 45, 55);
				if (emp1.getTime() < emp2.getTime())
						document.write("emp1 is lesser than emp2");
				else if (emp1.getTime() > emp2.getTime())
						document.write("emp1 is greater than emp2");
				else
						document.write("both are equal");
		</script>
		</body>
</html>
Output :
emp1 is greater than emp2

It will help you...

Share: