MySQL:如何检查字符串是否为有效的DATE,TIME或DATETIME [英] MySQL: How to check if a string is a valid DATE, TIME or DATETIME
问题描述
当我尝试将值放入无效的DATE字段时,MySQL似乎使用0000-00-00。有没有办法我可以做这个检查而不更新DATE字段?并且要从PHP中获取这个数据?
像是,有一种方法可以查询MySQL服务器并询问嘿,这个DATE,TIME或DATETIME是否有效你是否可以使用更好的方法?
div>
您可以根据要使用的格式解析日期,然后调用checkdate来测试是否为有效日期。请确保您阅读了有关 http://php.net/manual/en/function的评论。 checkdate.php 。
When I try to put a value into a DATE field which is invalid, MySQL seems to use 0000-00-00 instead. Is there a way I can do this "check" without updating a DATE field? And to do it from for example PHP?
Like, is there a way I can query the MySQL server and ask "Hey, is this DATE, TIME or DATETIME valid to you?"
Or is there maybe an even better way of doing it?
You could parse the date according to the format you want to use and then call checkdate to test if it's a valid date. Make sure you read the comments on http://php.net/manual/en/function.checkdate.php.
这篇关于MySQL:如何检查字符串是否为有效的DATE,TIME或DATETIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!