Home > Database > Mysql Tutorial > How to Group MySQL Entries by Date from a DATETIME Column?

How to Group MySQL Entries by Date from a DATETIME Column?

Susan Sarandon
Release: 2024-10-30 21:52:30
Original
953 people have browsed it

How to Group MySQL Entries by Date from a DATETIME Column?

Casting DATETIME to DATE in MySQL

Question:

When attempting to group database entries by date, despite having a datetime field, the following query fails:

select * from follow_queue group by follow_date cast follow_date as date
Copy after login

Answer:

To convert a DATETIME field to a DATE value for grouping, utilize the DATE() function:

select * from follow_queue group by DATE(follow_date)
Copy after login

The DATE() function extracts the date component from a DATETIME field, removing the time portion, and returning the result as a DATE value. This allows you to group entries by date, even if the underlying data is stored as datetime.

The above is the detailed content of How to Group MySQL Entries by Date from a DATETIME Column?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template