A Simple Formatter to Convert Timestamp to Age, representing the time elapsed from the provided timestamp till the current date and time.
Displays human-readable time spans in terms of years, months, days, hours, minutes, and seconds.
This is an excellent formatter, thanks for posting…!
I had to come back to this post, I cant believe how many times I’ve used this formatter, it’s so simple yet so useful! I’m finding myself putting it into places I hadn’t even thought of, its creating a much better user experience for some of the stuff I’m working on. I’m doing booking systems right now and this has popped up at just the right time.
I've recently discovered this and am trying to get it to work on 6.7 and can't seem to get it to display am I missing a something?
Hi @dbatesmdbctech,
Just tested it, didn't see any issue.
('2024-01-02').timestampToAge() gives me 171 days ago.
Ah thats partially it when it said timestamp I was convering the value to a timestamp
now to figure out what the code is to show this as years ago
heres an example of what your code will look like: {{serverconnectform1.data.GlobalSeoQuery.SeoDateAdded.timestampToAge()}}
The picker will append this to your date: .timestampToAge()
I got that thats how it works now I think what I may be looking at is Really I need to return years like how old the user is now
so I think I need to modify the code to be able to deal with years
so I would need to add the years var
var days = Math.floor(timeDifferenceInSeconds / 86400) % 365;
var years = Math.floor(timeDifferenceInSeconds / 31536000);
and then modify the date formatter
function formatTimeAgo(years, days, hours, minutes, seconds) {
if (years > 0) {
return years + "years" + (years > 1 ? "s" : "") + " ago";
} else if (days > 0)
and add years
return formatTimeAgo(years, days, hours, minutes, seconds);
Maybe this will help. No need for a custom formatter.