How To Check If Date is Older Than 1 Year in JavaScript?


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


Hello Friends,

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

Here i will give you many example how you can check if date is older than 1 year javascript.

Example : 1
<!DOCTYPE html>
<html>
		<head>
				<meta charset="utf-8">
				<title> How To Check If Date is Older Than 1 Year in JavaScript? - MyWebtuts.com </title>
		</head>
		<body>
		<script type="text/javascript">
				var oldDate = new Date("July 21, 2020 01:15:23");
				var todayDate = new Date();

				if(oldDate < todayDate) {
				    	document.write("it has been over one year!");
				} else {
				    	document.write("it has not gone one year yet!");
				}
		</script>
		</body>
</html>
Output :
it has been over one year!
Example : 2
<!DOCTYPE html>
<html>
		<head>
				<meta charset="utf-8">
				<title> How To Check If Date is Older Than 1 Year in JavaScript? - MyWebtuts.com </title>
		</head>
		<body>
		<script type="text/javascript">
				var oldDate = new Date("July 21, 2021 01:15:23");
				var newDate = new Date();

				if(oldDate < newDate) {
				    	document.write("it has been over one year!");
				} else {
				    	document.write("it has not gone one year yet!");
				}
		</script>
		</body>
</html>
Output :
it has not gone one year yet!

It will help you...

Share: