I am getting dates from 2 different API endpoints and saving them to MongoDB using Mongoose (used date in the schema).
Here is an example of the 2 dates in the database. Using dayjs, one of them works correctly and the other one shows in 2 hours instead of X minutes ago for example.
correct: 2022-01-11T16:05:05.000+00:00
incorrect: 2022-01-11T17:41:50.000+00:00
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
dayjs.extend(relativeTime);
{dayjs(data.paperDate).fromNow()} // returns 'in 2 hours'
Is there something wrong with the date marked as 'incorrect' ?
see https://momentjs.com/docs/
moment(new Date(2021)).fromNow(); // a year ago
moment(new Date(2021)).from(new Date(2012))