Created
March 4, 2023 23:58
-
-
Save sfaut/5f661074f03d1200942265e9b0ab9779 to your computer and use it in GitHub Desktop.
Converts a number of seconds since year 0 to a DATETIME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Converts a number of seconds since year 0 to a DATETIME | |
-- MySQL counterpart of TO_SECONDS() : https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_to-seconds | |
-- Author : sfaut <https://github.com/sfaut> | |
-- Publication date : 2023-03-05 | |
-- Tested with MySQL 8.0.32 (@@sql_mode='ANSI,TRADITIONAL') | |
CREATE FUNCTION FROM_SECONDS(seconds BIGINT) | |
RETURNS DATETIME | |
DETERMINISTIC | |
COMMENT 'Converts a number of seconds since year 0 to a DATETIME' | |
RETURN DATE'0000-01-01' + INTERVAL seconds SECOND - INTERVAL 1 DAY; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment