当mysql中输入为空时,为date_format返回空 [英] Return null for date_format when input is null in mysql

查看:937
本文介绍了当mysql中输入为空时,为date_format返回空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做这样的事情:

SELECT date_format(mydate, '%d/%m/%Y') FROM xyz;

当mydate为NULL时,date_format返回00/00/0000.这是正确的,但是如何使它在输入为NULL时返回NULL?

When mydate is NULL, date_format returns 00/00/0000. This is correct, but how can I make it so that it returns NULL when the input is NULL?

推荐答案

SELECT IF(mydate,date_format(mydate, '%d/%m/%Y'),NULL) FROM xyz;

来源: http://dev.mysql. com/doc/refman/5.0/en/control-flow-functions.html

这篇关于当mysql中输入为空时,为date_format返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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