Link to home
Start Free TrialLog in
Avatar of john M
john MFlag for United States of America

asked on

mysql test a date friend for value greater then zeroes

new to mysql know tsql
i see where we store dates with a 0000-00-00
how do i test for a   date  that does not have zeroes
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Give us an example of what you're trying to pull off here.

'Does not have zeros' means something like 6/9/2014?
ASKER CERTIFIED SOLUTION
Avatar of gplana
gplana
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of john M

ASKER

yes i mean '0000-00-00 in the date field.
There should be a function you can call to exclude the records.
I found if you use the field like in datediff of add a day it will exclude all '0000-00-00'
I think you can exclude them just adding  this to your WHERE clause:

AND your_date <> '0000-00-00'

Open in new window


or by adding this on your WHERE clause:
AND YEAR(your_date)<>0 

Open in new window


hope this helps.
where of course "your_date" means the name of the field that could have the wrong date.
>yes i mean '0000-00-00 in the date field.
I'm guessing that these values are stored in a character field, as 0000-00-00 is not in valid date format.
Running the below code in SSMS will throw an error:
CREATE TABLE #dates (dt date) 
INSERT INTO #dates (dt) 
VALUES('0000-00-00') 

Open in new window

So, assuming varchar, you can filter these rows out by using (as posted above)
WHERE your_date <> '0000-00-00'

Open in new window

, or in a single column by using
SELECT CASE your_date
   WHEN '0000-00-00'  THEN 'add something here to replace this value
   ELSE your_date
END 

Open in new window

JimHorn, mysql allows to store this "special" date value of 0000-00-00, it musn't be a varchar.

Your solution:
WHERE your_date <> '0000-00-00'
is exactly the same I have said.