Dzhuneyt
Dzhuneyt

Reputation: 8701

Is A Datetime Column's Value the Default One

I have a MySQL table and a column of type datetime. It's default value is something like 0000-00-00 00:00:00.

How do I check if a given row's value on this datetime column is the above by using native MySQL query functionality. E.g. without using "SELECT * FROM table WHERE my_date<>'0000-00-00 00:00:00'", because this leaves room for errors on different MySQL servers and configurations I believe.

Upvotes: 0

Views: 265

Answers (2)

beyerss
beyerss

Reputation: 1352

You could do something like "SELECT * FROM table WHERE my_date > '1970-01-01 00:00:00". 1/1/1970 is the commonly used epoch date.

Upvotes: 0

juergen d
juergen d

Reputation: 204894

SELECT * FROM table WHERE my_date <> 0

You can test it with

select cast('0000-00-00 00:00:00' as datetime) = 0

which returns true (and false for all other datetime values).

Upvotes: 1

Related Questions