Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140131

Comparing different date formats [duplicate]

$
0
0

This question already has an answer here:

I have the following:

DATE_FORMAT=YYYY-MM-DD HH:mm:ss
const differenceInDays = require('date-fns/difference_in_days');

const newDateNow = () => {
    const date = new Date();
    return formatDate(date, process.env.DATE_FORMAT);
};

const isValid = (expdate) => {
  today = newDateNow();
  differenceInDays(expdate, today) >= 0;
};

Now in a method I have:

const c = isValid(a);

this returns false, where I would expect true. Logging the variables I have:

today = 2019-12-12 17:55:48
expdate = 2020-10-09T22:00:00.000Z

So they have different date formats, which might be the reason isValid returns valid even though it should be true (given that a is further into the future than date).

How can I make this work? Should I perhaps transform the date format of a to something similar of date? (but how to do that?)


Viewing all articles
Browse latest Browse all 140131

Trending Articles