Home > Database > Mysql Tutorial > How to Convert Unix Timestamps to Human-Readable Dates in MySQL?

How to Convert Unix Timestamps to Human-Readable Dates in MySQL?

DDD
Release: 2024-11-30 07:18:14
Original
323 people have browsed it

How to Convert Unix Timestamps to Human-Readable Dates in MySQL?

Humanizing Unix Timestamps with MySQL's FROM_UNIXTIME() Function

Question:

How can I convert Unix timestamps, stored in a MySQL database field, into human-readable date formats?

Answer:

To efficiently convert Unix timestamps into a user-friendly format within MySQL, leverage the built-in FROM_UNIXTIME() function. This powerful function allows you to transform timestamp values into human-readable date formats.

Syntax:

SELECT
  FROM_UNIXTIME(timestamp) 
FROM 
  your_table;
Copy after login

Example:

Suppose you have a field named timestamp that stores Unix timestamps. To retrieve the corresponding human-readable dates, execute the following query:

SELECT
  FROM_UNIXTIME(`timestamp`) AS formatted_date 
FROM 
  your_table;
Copy after login

This query returns a new column named formatted_date that contains the humanized dates.

Additional Information:

  • The FROM_UNIXTIME() function supports various date formatting options. By using format specifiers, you can customize the output date format. For more details, refer to the MySQL documentation on FROM_UNIXTIME().
  • This function is incredibly versatile and can be employed in various scenarios, such as displaying timestamps in chronological order, filtering records based on date ranges, and performing date-related calculations.

The above is the detailed content of How to Convert Unix Timestamps to Human-Readable Dates in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template