10 examples of 'compare two dates in jquery' in JavaScript

Every line of 'compare two dates in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
45export function datesAreEqual(date1: Date, date2: Date) {
46 if (date1 instanceof Date && date2 instanceof Date) {
47 return (
48 date1.getFullYear() === date2.getFullYear() &&
49 date1.getMonth() === date2.getMonth() &&
50 date1.getDate() === date2.getDate()
51 );
52 } else {
53 return false;
54 }
55}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

19function daysAreSame(date1,date2){
20
21 var month1 = date1.getMonth();
22 var day1 = date1.getDate();
23 var year1 = date1.getFullYear();
24
25 var month2 = date2.getMonth();
26 var day2 = date2.getDate();
27 var year2 = date2.getFullYear();
28
29 return month1==month2 && day1 == day2 && year1 == year2;
30}
6export default function areDatesEqual(date1, date2) {
7 return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate(); // TODO: UTC-comparison
8}
10function compareDateString(datetime1, datetime2)
11{
12 var date1 = new Date(datetime1);
13 var date2 = new Date(datetime2);
14
15 return (date1 - date2);
16}
11export default function sortDates(
12 arrayOfDates: Array<moment$Moment>
13): Array<moment$Moment> {
14 return arrayOfDates.sort(compareMomentDates);
15}
15export function date_sort_asc (date1: Date, date2: Date) {
16 // This is a comparison function that will result in dates being sorted in
17 // ASCENDING order. As you can see, JavaScript's native comparison operators
18 // can be used to compare dates. This was news to me.
19 if (date1 > date2) return 1;
20 if (date1 < date2) return -1;
21 return 0;
22}
8static dateTimeCompararer(value1, value2) { return (value1.getTime() == value2.getTime()); }
86function sortDate(a, b) {
87 return b.timestamp - a.timestamp;
88}
61function compareTime (a, b) {
62 return a.date.getTime() >= b.date.getTime() ? 1 : -1
63}
140export function isBetweenDates(dateToCheck, startDate, endDate) {
141 return (!(isBeforeDate(dateToCheck, startDate)) &&
142 !(isAfterDate(dateToCheck, endDate)));
143}

Related snippets