MySQL 5.1 implicit cast from now() to a date field
Posted
by Savageman
on Stack Overflow
See other posts from Stack Overflow
or by Savageman
Published on 2010-04-27T17:26:33Z
Indexed on
2010/04/27
17:33 UTC
Read the original article
Hit count: 324
mysql
|implicit-cast
Hello,
I have an issue with MySQL 5.1. A datetime data type isn't implicitly casted to match a date column.
SELECT * FROM my_table WHERE my_date_field = NOW()
This request doesn't return any rows using MySQL 5.1, but works well with version 5.0.
If we use CURDATE()
instead of NOW()
it works both in MySQL 5.0 and MySQL 5.1.
If the cast is explicit (CAST(NOW() AS DATE)
), it also works both in MySQL 5.0 and MySQL 5.1.
The problem only appears with implicit cast from datetime to date. Doesn't anyone already encountered this issue or has a clue about how to solve this problem? I know it's not the best to use NOW() instead of CURTIME(), but this isn't the question here. It is currently used in an application and the purpose is to avoid rewriting everything.
Thanks!
© Stack Overflow or respective owner