In this article, you will learn how to Compare Dates in Javascript. Let’s say you have two dates: 14 / 2 / 2020 and 14 / 2 / 2021.
In this article, you will learn how to Compare Dates in Javascript.
Let’s say you have two dates: 14 / 2 / 2020
and 14 / 2 / 2021
.
var date1 = new Date(2021, 02, 14);
var date2 = new Date(2020, 02, 14);
Copy
In order to compare dates, you can use the getTime()
method and a strict equality comparison ===
.
var date1 = new Date(2021, 02, 14);
var date2 = new Date(2020, 02, 14);
if (date1.getTime() === date2.getTime())
console.log("The dates are equal");
else
console.log("The dates are not equal");
Copy
Note: The getTime
method functions by returning the number of milliseconds between the midnight of 1/1/1970 and the supplied date.
4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.
Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.
Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.
JavaScript Tutorial | JavaScript Code Examples. Free JavaScript code examples from codepen.io and libraries from github.io: buttons, hover effects, loaders, modal windows, text effects, menu and other.
Don’t waste time writing long code while you can make it short, yet clearer and easier to read. In this Javascript tutorial, we'll discuss 15 Simple Coding Techniques to Get Your Tasks Done with Shorter Code in JavaScript