10 examples of 'javascript compare dates without time' in JavaScript

Every line of 'javascript compare dates without time' 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
140export function isBetweenDates(dateToCheck, startDate, endDate) {
141 return (!(isBeforeDate(dateToCheck, startDate)) &&
142 !(isAfterDate(dateToCheck, endDate)));
143}
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}
10function compareDateString(datetime1, datetime2)
11{
12 var date1 = new Date(datetime1);
13 var date2 = new Date(datetime2);
14
15 return (date1 - date2);
16}
39export function minDate(a, b) {
40 if (a && b) {
41 return a > b ? b : a;
42 }
43 return a || b;
44}
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}
128function dateDiff(start, end) {
129 return moment(start).diff(end, 'minutes');
130}
96gt(date: Date): boolean {
97 return this.date > date;
98}
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}
187function formatDateRange(timeFrom, timeTo) {
188 const dateFrom = new Date(timeFrom)
189 const dateTo = new Date(timeTo)
190
191 let string
192 if (dateFrom.getDate() == dateTo.getDate() && dateFrom.getMonth() == dateTo.getMonth() && dateFrom.getFullYear() == dateTo.getFullYear()) {
193 string = formatDate(dateFrom)
194 } else if (dateFrom.getMonth() == dateTo.getMonth() && dateFrom.getFullYear() == dateTo.getFullYear()) {
195 string = `${dateFrom.getDate()}${dateTo.getDate()} ${MONTHS[dateFrom.getMonth()]} ${dateFrom.getFullYear()}`
196 } else if (dateFrom.getMonth() != dateTo.getMonth() && dateFrom.getFullYear() == dateTo.getFullYear()) {
197 string = `${dateFrom.getDate()} ${MONTHS[dateFrom.getMonth()]}${dateTo.getDate()} ${MONTHS[dateTo.getMonth()]} ${dateFrom.getFullYear()}`
198 } else {
199 string = `${dateFrom.getDate()} ${MONTHS[dateFrom.getMonth()]} ${dateFrom.getFullYear()}${dateTo.getDate()} ${MONTHS[dateTo.getMonth()]} ${dateTo.getFullYear()}`
200 }
201
202 return string
203}
126function isInDateRange(firstDate: number, lastDate: number) {
127 return (p: IBucket) => p.x >= firstDate && p.x <= lastDate;
128}

Related snippets