如果mysql数据类型是时间戳,默认值为“0000-00-00 00:00",如何检查是否为空? [英] how to check null or not if mysql datatype is timestamp with a default value of "0000-00-00 00:00"?

查看:230
本文介绍了如果mysql数据类型是时间戳,默认值为“0000-00-00 00:00",如何检查是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找出返回 truefalse 的最佳方法,如果 mysql 数据类型是 TIMESTAMP 是 null 返回日期 >0000-00-00 00:00

I want to figure out the best way to return true or false if a mysql datatype is TIMESTAMP which is null returns date 0000-00-00 00:00

我试过这样的 -

if($mycolumn == "0000-00-00 00:00") {
    echo "null";
} else {
    echo "not null";
}

这是时间戳列的mysql -

last_login TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'

我可以知道这是否不是工作的方式,那么我如何最好地检查它是否为空时间..?

Can I get to know if this is not the way to the job, then how do I best check for that as a null time or not..?

谢谢.

推荐答案

我认为对你来说最好的方法是使用这个 方法

I think the best way for you is to use this method

SELECT  IF(last_login = '0000-00-00 00:00:00', "null", "not null") as last_login from ...

这篇关于如果mysql数据类型是时间戳,默认值为“0000-00-00 00:00",如何检查是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆