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?
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.
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.