9 examples of 'datediff javascript' in JavaScript

Every line of 'datediff 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
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}
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

128function dateDiff(start, end) {
129 return moment(start).diff(end, 'minutes');
130}
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}
18function diff(value, unit = 'day') {
19 const days = dayjs(value).diff(dayjs(), unit)
20 const units = Math.abs(days) === 1 ? 'day' : 'days'
21
22 if (days === 0) {
23 return 'today'
24 }
25
26 return days > 0
27 ? 'in ' + Math.abs(days) + ' ' + units
28 : Math.abs(days) + ' ' + units + ' ago'
29}
39function getDiff (date1, date2, unit) {
40 return date1.diff(date2, unit)
41}
71public getDiff(date: Dayjs, comparing: Dayjs, units?: any, float?: any) {
72 return date.diff(comparing, units, float);
73}
79function getDayDiff(date1, date2) {
80 return Math.floor((getZeroStamp(date1) - getZeroStamp(date2)) / DAY_TIMESTAMP)
81}
9static diff(start: Date, end: Date, unit: 'h' | 'm' = 'h', offset: number = 0): number {
10 const timeDiff = Math.abs(end.getTime() - start.getTime() + offset);
11 return parseInt((timeDiff / (unit === 'h' ? DateUtil.HOUR : DateUtil.MINUTE)) + '');
12}
53function diffDates(now, then) {
54 const diff = then - now;
55 let remaining = diff;
56 const days = Math.floor(remaining / dayMs);
57 remaining = remaining % dayMs;
58 const hours = Math.floor(remaining / hourMs);
59 remaining = remaining % hourMs;
60 const minutes = Math.floor(remaining / minMs);
61 remaining = remaining % minMs;
62 const seconds = Math.floor(remaining / secMs);
63 remaining = remaining % secMs;
64
65 return {
66 days: addZeros(days),
67 hours: addZeros(hours),
68 minutes: addZeros(minutes),
69 seconds: addZeros(seconds),
70 };
71}

Related snippets