I have a column in a MySQL database that contains a date as milliseconds (epoch). I want to build an SQL query that formats the date as something human readable (day, month, yea
CREATE DEFINER=`root`@`localhost` FUNCTION `ConvertTimeDelta`(duration int) RETURNS
varchar(20) CHARSET utf8mb4
DETERMINISTIC
BEGIN
DECLARE time_delta VARCHAR(20);
DECLARE date_format VARCHAR(20);
SET date_format = IF (duration > 3599999, '%H:%i:%s', '%i:%s');
SET time_delta = TIME_FORMAT(SEC_TO_TIME(duration/1000), date_format);
RETURN time_delta;
END
For example select ConvertTimeDelta(4800240) result = 01:20:00 select ConvertTimeDelta(35076) result = 00:35