Jump to content

Problem with dates in 5.1.40


semiller

Recommended Posts

I recently upgraded to 4.1.8 to 5.1.40 in doing so the query:

select count(id) from TABLE where DateField >=2009-11-01' and DateField <='2009-11-05'

ignores the results from 2009-11-01 as if it was > instead of >= I have tested with the cast function and that works but do not want to rewrite every query to fix. Is there a solution or bug, or incompatible issue in 5.0 or 5.1 to this?

 

mysql [db]> select count(id) from TABLE where DateField>='2008-01-5';

+-----------+

| count(id) |

+-----------+

|        1 |

+-----------+

 

mysql [db]> select count(id) from TABLE where DateField>= cast('2008-01-5' as date);

+-----------+

| count(id) |

+-----------+

|        2 |

+-----------+

Link to comment
https://forums.phpfreaks.com/topic/180924-problem-with-dates-in-5140/
Share on other sites

  • 2 weeks later...

It's incompatible.

 

"Incompatible change: Beginning with MySQL 5.0.42, when a DATE value is compared with a DATETIME value, the DATE value is coerced to the DATETIME type by adding the time portion as 00:00:00. Previously, the time portion of the DATETIME value was ignored, or the comparison could be performed as a string comparison. To mimic the old behavior, use the CAST() function to cause the comparison operands to be treated as previously."

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.