SELECT FROM_UNIXTIME(event_time, '%Y') AS year, COUNT(id) AS total FROM events GROUP BY FROM_UNIXTIME(event_time, '%Y') DESC;
If we want to group records by date in a MySQL table where the value is stored as a Unix timestamp, we can use
FROM_UNIXTIME() function in the
GROUP BY clause.
If we want to group by date only (without time), we can use the corresponding date formatting string as the second parameter.
- Convert Unix timestamp to human readable date in MySQL
- Group by year of Unix timestamp in MySQL
- Count total rows by year in MySQL
- Convert INT to DATETIME in MySQL
- Select year from a 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