10 examples of 'compare dates typescript' in JavaScript

Every line of 'compare dates typescript' 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
11export default function sortDates(
12 arrayOfDates: Array<moment$Moment>
13): Array<moment$Moment> {
14 return arrayOfDates.sort(compareMomentDates);
15}
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

46public sortByDateTimeHelper(a: Date, b: Date): number {
47 if (a < b) {
48 return -1;
49 }
50
51 if (a > b) {
52 return 1;
53 }
54
55 return 0;
56}
361articles.sort(function dateSorter(a, b) {
362 return (Date.parse(b.date)) - (Date.parse(a.date));
363});
115function compareByEndDate(a, b) {
116 let comparison = 0;
117 if (a.endTime > b.endTime) {
118 comparison = 1;
119 } else if (a.endTime < b.endTime) {
120 comparison = -1;
121 }
122 return comparison * -1;
123}
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}
167export function sortByDate (a, b) {
168 return a.date - b.date
169}
34function sortByDate(a, b) {
35 if (a.publishedOn < b.publishedOn) {
36 return 1;
37 } else if (a.publishedOn > b.publishedOn) {
38 return -1;
39 }
40 return 0;
41}
86function sortDate(a, b) {
87 return b.timestamp - a.timestamp;
88}
18compare(a: Pod, b: Pod) {
19 return new Date(a.startTime).getTime() - new Date(b.startTime).getTime();
20}
10function compareDateString(datetime1, datetime2)
11{
12 var date1 = new Date(datetime1);
13 var date2 = new Date(datetime2);
14
15 return (date1 - date2);
16}

Related snippets