9 examples of 'compare date with current date in javascript' in JavaScript

Every line of 'compare date with current date in javascript' 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
10function compareDateString(datetime1, datetime2)
11{
12 var date1 = new Date(datetime1);
13 var date2 = new Date(datetime2);
14
15 return (date1 - date2);
16}
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

1297function get_date_diff(d1,d2) {
1298 d1 = new Date(d1);
1299 d2 = new Date(d2);
1300 var diff = d1 - d2;
1301 var min_same = d1.getMinutes() === d2.getMinutes();
1302 var hour_same = d1.getHours() === d2.getHours();
1303 var isDateSame = d1.toLocaleDateString() === d2.toLocaleDateString();
1304 if(diff <= 60*1000 && hour_same && min_same && this.show_terse_dates_)
1305 return null;
1306 else
1307 return RCloud.utils.format_date_time_stamp(d1, diff, isDateSame, true, this.show_terse_dates_);
1308}
6export function playdate(date1: Date, date2: DateAlias): Date {
7 return new Date(date2.getTime() - date1.getTime())
8}
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}
121function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式
122 var aDate, oDate1, oDate2, iDays;
123 aDate = sDate1.split("-");
124 oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //转换为12-18-2002格式
125 aDate = sDate2.split("-");
126 oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
127 iDays = parseInt((oDate1 - oDate2) / 1000 / 60 / 60 /24); //把相差的毫秒数转换为天数
128 return iDays
129}
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}
1export function dateIsGreaterThan(dateA: string | Date, dateB: string | Date) {
2 return new Date(dateA) > new Date(dateB);
3}
66function getCurrentDate() {
67 date = $("#date-picker").val();
68 time = $("#spinner").val();
69 millis = Date.parse(date + " " + time + " GMT");
70 return new Date(millis)
71}
86function sortDate(a, b) {
87 return b.timestamp - a.timestamp;
88}

Related snippets