MySQL Forums
Forum List  »  Newbie

IfNull and Date Formats
Posted by: Derek McKinnon
Date: June 07, 2018 07:16PM

I have worked with IfNull since moving over from SQL Server and IsNULL for a few years.

It is scattered throughout the code I inherited, and as far as I can see has always worked correctly.

Now I am having trouble with IfNULL and dates that are hand coded into the SQL string.

Here is a snippet showing the problem.


SELECT IFNULL(e.EnrolmentEndDate, 29991231), (IFNULL(e.EnrolmentEndDate, 29991231) >= 20180610), e.EnrolmentEndDate >= 20180610 FROM Enrolment e WHERE e.id = 1

The results from this are

"2018-06-24" "0" "1"

Changing the second field to using 2018-06-10 results in the answer I would have expected.

While I can easily code around this in this circumstance, I'm worried that I now need to test everywhere in the program that IfNull is used with Date fields.

I'm using version 5.6 of MySQL.

Options: ReplyQuote


Subject
Written By
Posted
IfNull and Date Formats
June 07, 2018 07:16PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.