MySQL Forums
Forum List  »  Newbie

Re: Calculating TIME ELAPSED SINCE in days OR hours OR minutes
Posted by: Dan LeGate
Date: February 27, 2009 05:40PM

Yup, got it working by removing Aliases (sure would be nice to be able to use them to make this code more compact):
SELECT TIMESTAMPDIFF(MINUTE, date_updated, now()) as MinutesElapsed,
CASE
WHEN TIMESTAMPDIFF(MINUTE, date_updated, now()) < 60 THEN concat(FORMAT(TIMESTAMPDIFF(MINUTE, date_updated, now()), 1), " minutes")
WHEN TIMESTAMPDIFF(MINUTE, date_updated, now()) > 60 and TIMESTAMPDIFF(MINUTE, date_updated, now()) < 1440 THEN concat(FORMAT(TIMESTAMPDIFF(MINUTE, date_updated, now())/60, 1), " hours")
WHEN TIMESTAMPDIFF(MINUTE, date_updated, now()) > 1440 THEN concat(FORMAT(TIMESTAMPDIFF(MINUTE, date_updated, now())/1440, 1), " days") END as "The Display"from time_elapsed
Thanks for all your help, both of you!

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.