Dima Malko
Dima Malko

Reputation: 283

Convert seconds to Timestamp, and compare values, Firebase, React

I need to compare two values, as you see in my code below.

Point is that they are in different formats, and i need them to compare.

Here is my code(daysToLeave is allways number 1-3 - this value match 1-3 days):

const tomorrow = new Date();
const tmp = tomorrow.getDate() + daysToLeave;
tomorrow.setDate(tmp);

console.log("eventDate.date", eventDate?.date);
console.log("tommorrow", tomorrow);

if (eventDate?.date < tomorrow) {
  console.log("success");
}

Here are my console.logs: enter image description here

Upvotes: 0

Views: 141

Answers (1)

Irmak Coşar Şahna
Irmak Coşar Şahna

Reputation: 204

use moment and .diff().

//Determine the unit of difference between
    const type = ["years","months","weeks","days","hours","minutes"]


    moment(tomorrow).diff(eventDate?.date.toDate(), type[3])

Upvotes: 1

Related Questions