Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to compare 2 dates in format DD/MM/YYYY with JavaScript

const date1 = '25/02/1985';
const date2 = '26/02/1985';

// input 28/10/2018
// input DD/MM/YYYY
export const convertToDate = (dateSting) => {
    const [day, month, year] = dateSting.split("/");
    return new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
}

console.log(convertToDate(date1) > convertToDate(date2))
Comment

javascript compare dates

let d1 = new Date();
let d2 = new Date();
// can use >, <, <=, <=
d1 > d2
d1 >= d2
// == won't work so can use this:
(d1 >= d2) && (d2 >= d1)
Comment

javascript compare dates

let myDate = new Date("January 13, 2021 12:00:00");
let yourDate = new Date("January 13, 2021 15:00:00");

if (myDate < yourDate) {
  console.log("myDate is less than yourDate"); // will be printed
}
if (myDate > yourDate) {
  console.log("myDate is greater than yourDate");
}
Comment

How to compare two different date formats in javascript

const d1 = new Date("Mon Jan 3 2022 16:38:58 GMT+0530 (India Standard Time)") 
const d2 = new Date("2022-01-03T18:30:00Z")
console.log(d1)
console.log(d2)

if (d1 < d2) console.log("Date 1 is earlier than d2")

// To find hh:mm:ss difference for the same day we can do this. 
console.log(new Date(d2-d1).toISOString().substr(11, 8))
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript map method 
Javascript :: what is prototype in javascript 
Javascript :: search for diff in two JSON 
Javascript :: try without catch 
Javascript :: array indexof 
Javascript :: autocomplete html in react 
Javascript :: call two functions onpress react native 
Javascript :: tinymce react 
Javascript :: javascript create array 
Javascript :: vscode react snippets 
Javascript :: jquerey dropdown button 
Javascript :: delete item from array of objects javascript 
Javascript :: Modify String with Uppercase 
Javascript :: how to add a property to a class in javascript 
Javascript :: if array includes string 
Javascript :: chrome-aws-lambda 
Javascript :: javascript in python 
Javascript :: js sort array 
Javascript :: gettimezoneoffset javascript 
Javascript :: react native modal 
Javascript :: break loop if condition is met 
Javascript :: remove element json javascript 
Javascript :: Set an onclick function with a parameter for an element 
Javascript :: dom manipulation js 
Javascript :: npm whatsapp api 
Javascript :: javaScript throw statement 
Javascript :: jquery method 
Javascript :: props history 
Javascript :: react window navigate 
Javascript :: random string javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =