"Time Ago..." relative time in the style of social media

This is either a tips and tricks post or itโ€™s a call to make this better. Could go either way!

Hereโ€™s an app that demonstrates โ€œtime agoโ€. Is there a better way to do this?

https://www.appsheet.com/samples/Demonstrates-the-classic-Time-Ago-calc-a-la-social-media?appGuidStr...

First we need a calc named โ€œTime ago in Secondsโ€ which is a unix timestamp derived from a Datetime field called โ€œTimestampโ€:

((HOUR(DATE(NOW()) - โ€œ01/01/1970โ€))*3600 + (MOD(HOUR(NOW() - โ€œ01/01/1970โ€),HOUR(DATE(NOW()) - โ€œ01/01/1970โ€)))*3600 + MINUTE(NOW() - โ€œ01/01/1970โ€)*60 + SECOND(NOW() - โ€œ01/01/1970โ€)) -
((HOUR(DATE([Timestamp]) - โ€œ01/01/1970โ€))*3600 + (MOD(HOUR([Timestamp] - โ€œ01/01/1970โ€),HOUR(DATE([Timestamp]) - โ€œ01/01/1970โ€)))*3600 + MINUTE([Timestamp] - โ€œ01/01/1970โ€)*60 + SECOND([Timestamp] - โ€œ01/01/1970โ€))

Then we need a IFS() calculation that looks like so:

ifs(
[Time ago in Seconds] < 0, "hasn't happened yet, why worry?",
[Time ago in Seconds] < 5, "just now",
[Time ago in Seconds] < 15, "a few seconds ago",
[Time ago in Seconds] < 60, [Time ago in Seconds] & "s ago",
[Time ago in Seconds] < 3600, [Time ago in Seconds]/60 & "m ago",
[Time ago in Seconds] < 86400, ([Time ago in Seconds]/60)/60 & "h ago",
[Time ago in Seconds] < 604800, (([Time ago in Seconds]/60)/60)/24 & "d ago",
[Time ago in Seconds] < 2419200, ((([Time ago in Seconds]/60)/60)/24)/4 & "w ago",
[Time ago in Seconds] < 29030400, ((((([Time ago in Seconds]/60)/60)/24)/4)/12)+1 & "mo ago",
[Time ago in Seconds] >= 29030400, ((((((([Time ago in Seconds]/60)/60)/24)/4)/12)+1)/12)+1 & "y ago"
)

Open to ideas hereโ€ฆ thanks for reading.

10 4 456
4 REPLIES 4

TOTALSECONDS(NOW() - [Timestamp])

While not a Unix timestamp calc, it should produce the same result.


thatโ€™s way cleaner, thank you!!

Thereโ€™s so many of these time-saving formulas that have been snuck into the system throughout the years.

A very useful concept as usual from you @TyAlevizos. Thank you.

If I may say, in essence, you have nicely converted the cryptic computer science language on the left-hand side of the expression into an art of human-friendly readable language on the right hand side.

Top Labels in this Space