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
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."

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.