|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
return value for date_format() when date field is NULL
Hi,
I cant find the answer on the manual pages. Maybe I should look harder. Basically I'm putting dates into a table using: Code:
date_format(INVOICEDATE, '%Y-%m-%d %H:%i:%s') As datei then I can select dates that have put an INVOICEDATE in by doing Code:
SELECT * FROM TABLE WHERE datei>'1' Only the reverse doesnt work, meaning I cant do a query for rows where no invoice date was entered (i.e. null) So I need to know exactly what value the date_format function returns when it comes accross a null value. I've tried echoing the result to the screen and it returns an empty string. |
|
#2
|
||||
|
||||
|
This question was so intriguing I looked into my own database.
And indeed, if i looked for the records select * from film where taal = null I got not a single record, although I knew there had to be some. Here's what I found at http://mysqld.active-venture.com/Pr..._with_NULL.html If you want to search for column values that are NULL, you cannot use the =NULL test. The following statement returns no rows, because expr = NULL is FALSE, for any expression: mysql> SELECT * FROM my_table WHERE phone = NULL;To look for NULL values, you must use the IS NULL test. The following shows how to find the NULL phone number and the empty phone number: mysql> SELECT * FROM my_table WHERE phone IS NULL;mysql> SELECT * FROM my_table WHERE phone = "";And so I changed my SQL statement Select * from film where taal = null into select * from film where taal is null and this time, I got the records I expected. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > return value for date_format() when date field is NULL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|