0

I want to check whether the date object Thu Apr 29 2021 01:15:00 GMT+0530 (India Standard Time) is before or after the current time, that is new Date().

I tried the basic < operator but it doesn't seem to work.

How do I achieve this? Thanks in advance.

vaibhav deep
  • 655
  • 1
  • 8
  • 27

2 Answers2

0

Convert your string to a Date object so that you can compare those two. Reference: MDN

const my_date = new Date("Thu Apr 29 2021 01:15:00 GMT+0530 (India Standard Time)")
const c_date = new Date()

console.log(my_date > c_date)
vanshaj
  • 499
  • 1
  • 4
  • 13
  • You don't need the second Date, `new Date(string) > Date.now()` will return the same result. – RobG Apr 29 '21 at 01:11
0

It should be working with the <> operators:

const d1 = new Date("Thu Apr 29 2021 01:15:00 GMT+0530");
let now = new Date();

[d1, now].forEach(d => console.log(d));

console.log(now > d1);          // false because now is less than d1
now.setDate(now.getDate() + 2); // add 2 days to the now date
console.log(now > d1);          // true because now is greater than d1
LaytonGB
  • 1,384
  • 1
  • 6
  • 20