I’m working on setting up a table that shows long it’s been since something has last been touched. I was to only show how many days have passed, and not have the cell reduce to something less accurate like months, to make comparison faster. For example, if something has been untouched for 45 days, right now JS is reducing that down to 1 month, when I want it to instead display 45 days
Right now, I’m currently using this to display time past, and I’ve seen solutions to change how the time may be represented, but only how to change the output, not reduce months to days
Cell: ({ value }) => {
return value ? dayjs(new Date(now - value)).fromNow() : null;
}
Any help is greatly appreciated!
2
Answers
fromNow
function gives you the relative time so45
days becomes a month(since it is close to a month). You can use thediff
function to return the result in the format "X days ago" where X is the exact day number.Note: Do not forget to add a logic for "day ago" and "days ago" to make it work for
1 day
or so.An easy workaround is to use the .diff function like so :