Custom AC Formatter - Timestamp to Age

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.

image

image

10 Likes

This is an excellent formatter, thanks for posting…!

1 Like

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.

1 Like

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

1 Like

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.

I've used this extension so many times now, it's been excellent. Today, I tried to use it in W7b25 and came up with the following error:

@Roney_Dsilva any ideas on what it could be?

Is the formatter JavaScript definitely included on your page?

Yes, its in the layout page:
image

This could possibly be a Wappler problem. I can select it in the picker but when I go back to the picker again it is not there, see this:
menuitems2

bug report may be useful if it is a wappler issue, i will certainly have a look at a report if the team can't if you post one. (or pm me it)

Never use this extension however looking at the error message is the syntax correct?

Should it be

TimestampToAge()

or should there be a dot there

Timestamp.ToAge()

I got it working, I removed extension, restarted Wappler then re-installed the extension again and it worked, must've just been an anomaly - thanks to everyone for pitching in.

1 Like

For future reference, I believe that screenshot is not related to this custom extension - that JS is from Wappler, not this custom extension

1 Like