SELECT FROM_UNIXTIME(event_time, '%Y') AS year FROM events;
If a MySQL database table has a Unix timestamp stored in an
INT field, it must first be converted to an easy-to-read format when generating a report.
This conversion can be done with the
FROM_UNIXTIME() function, which returns a representation of unix_timestamp as a DateTime or character string value.
If you want to refine this further, for example, if you only need the year value, you can use the
'%Y ' format string as a second parameter.
- Convert Unix timestamp to human readable date in MySQL
- Count total rows by year in MySQL
- Convert INT to DATETIME in MySQL
- Select year from a Unix timestamp in MySQL
- Group by year of Unix timestamp in MySQL
- Get current date in MySQL
- Get current year in MySQL
- Extract year from a date in MySQL
- Get last 30 days records in MySQL