When a timestamp column is defined as DEFAULT 0
, if it's not specified in INSERT or UPDATE, '0000-00-00 00:00:00' becomes the default value.
What's the proper way to check if such a timestamp is set thus not the default value?
SELECT * FROM table WHERE timestamp <> 0
It does seem to work but I'm not sure if it's the proper way and work 100% cases?
And when such value gets selected in PHP, how to check if it's set or not?
Thus far, I came up with something like this:
if ($row['timestamp'] != '0000-00-00 00:00:00') {
}
It does work but it seems tacky to me. I'm not so sure if its the proper way neither. What should I do instead?
In Php side you can use this
if ($row['timestamp'] > 0) { }
and
in mysql
SELECT * FROM table WHERE timestamp > 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With