Home >Database >Mysql Tutorial >Here are a few question-based titles that fit your provided article: * How Do I Convert Epoch Time to a Human-Readable Date in MySQL? * Converting Epoch Time to a Date in MySQL: A Step-by-Step Guide
Converting Epoch Time to Human Readable Date in MySQL
Epoch time, a timestamp representing seconds elapsed since January 1, 1970 UTC, is often stored in databases. Converting epoch time to a human-readable date format is crucial for data manipulation and visualization.
Consider the epoch value 1389422614485, stored in a VARCHAR data type. To convert it to human time, we can leverage the from_unixtime() function in MySQL along with mathematical operations:
select from_unixtime(floor(1389422614485/1000));
Epoch values with millisecond precision require division by 1000 to extract the timestamp in seconds. The floor() function ensures we work with the whole number of seconds. The result:
2014-01-11 12:13:34
Update for MySQL 8.0 (July 2020)
In MySQL 8.0, the floor function is no longer necessary when handling milliseconds:
select from_unixtime(1594838230234/1000);
This returns:
2020-07-15 18:37:10.2340
By understanding this conversion process, developers can easily transform epoch time values into human-readable dates for various analytical purposes, ensuring accurate and comprehensible data representation.
The above is the detailed content of Here are a few question-based titles that fit your provided article: * How Do I Convert Epoch Time to a Human-Readable Date in MySQL? * Converting Epoch Time to a Date in MySQL: A Step-by-Step Guide. For more information, please follow other related articles on the PHP Chinese website!