Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
557 B
2
Indexable
Never
DELIMITER $$
CREATE FUNCTION format_seconds(seconds INT)
RETURNS VARCHAR(100)
DETERMINISTIC
BEGIN
	DECLARE days INT;
    DECLARE hours INT;
    DECLARE minutes INT;
    
    SET days = seconds DIV (24 * 60 * 60);
    SET seconds = seconds - (days * 24 * 60 * 60);
    
    SET hours = seconds DIV (60 * 60);
    SET seconds = seconds - (hours * 60 * 60);
    
    SET minutes = seconds DIV 60;
    SET seconds = seconds - (minutes * 60);
    
    RETURN CONCAT(days, ' days ', hours, ' hours ', minutes, ' minutes ', seconds, ' seconds');
END $$
DELIMITER ;
Leave a Comment