How To Check If Date is Older Than 24 Hour in JavaScript?


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


Hello Friends,

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

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

Example : 1
<!DOCTYPE html>
<html>
		<head>
				<meta charset="utf-8">
				<title>JavaScript If Date Is Older Than 24hour - MyWebtuts.com </title>
		</head>
		<body>
		<script type="text/javascript">
				var date1 = new Date('07.30.2021 03:26');
				var timeStamp = Math.round(new Date().getTime() / 1000);
				var timeStampYesterday = timeStamp - (24 * 3600);
				var is24 = date1 >= new Date(timeStampYesterday*1000).getTime();
				document.write("Date is 24 hour older true or false? " +is24);
		</script>
		</body>
</html>
Output :
Date is 24 hour older true or false? true
Example : 2
<!DOCTYPE html>
<html>
		<head>
				<meta charset="utf-8">
				<title>JavaScript If Date Is Older Than 24hour - MyWebtuts.com </title>
		</head>
		<body>
		<script type="text/javascript">
				var date1 = new Date('07.28.2021 03:26');
				var timeStamp = Math.round(new Date().getTime() / 1000);
				var timeStampYesterday = timeStamp - (24 * 3600);
				var is24 = date1 >= new Date(timeStampYesterday*1000).getTime();
				document.write("Date is 24 hour older true or false? " +is24);
		</script>
		</body>
</html>
Output :
Date is 24 hour older true or false? false

It will help you...

Share: