Comparing DATE String with DATETIME Field in MySQL
It is indeed possible to compare a DATE string, such as "2010-04-29," with strings stored as DATETIME in MySQL. To achieve this, you can use the DATE() function.
The DATE() function extracts the date portion from a DATETIME field, discarding the time component. By using this function, you can compare the requested DATE string directly with the DATETIME field.
The following SQL query demonstrates how to accomplish this:
SELECT * FROM `calendar` WHERE DATE(startTime) = '2010-04-29'
This query will retrieve all rows from the calendar table where the date portion of the startTime field matches "2010-04-29." You will now be able to retrieve data accurately for entries in the table, even though they are stored as DATETIME.
The above is the detailed content of How to Compare a DATE String with a DATETIME Field in MySQL?. For more information, please follow other related articles on the PHP Chinese website!