简体   繁体   English

Mysql将00:00:00解释为凌晨12:00?

[英]Mysql interprets 00:00:00 as 12:00am?

So mysql has a time(type) in which it has a 24 hour clock stored that can ouput time in am/pm format with the mysql function date_format(). 所以mysql有一个时间(类型),它有一个24小时的时钟存储,可以使用mysql函数date_format()以am / pm格式输出时间。 The only problem is that when the user doesnt select the time, the value that stores in the mysql database is 00:00:00 which turns out to be 12:00am when i echo it with php. 唯一的问题是当用户没有选择时间时,存储在mysql数据库中的值是00:00:00,当我用php回显它时,结果是12:00 am。 So how would i frame it so it can tell a difference between a null value and 00:00:00 which is 12:00am? 那么我如何构建它以便它可以区分空值和00:00:00(凌晨12:00)之间的区别? (Btw, i try inserting null into the time column, turns out to be 00:00:00, which is 12:00am). (顺便说一句,我尝试在时间列中插入null,结果是00:00:00,即凌晨12:00)。

So how would i frame it so it can tell a difference between a null value and 00:00:00 which is 12:00am? 那么我如何构建它以便它可以区分空值和00:00:00(凌晨12:00)之间的区别? (Btw, i try inserting null into the time column, turns out to be 00:00:00, which is 12:00am). (顺便说一句,我尝试在时间列中插入null,结果是00:00:00,即凌晨12:00)。

Make the column nullable. 使列可以为空。 (Remove the NOT NULL constraint.) (删除NOT NULL约束。)

Its far better to validate the user input field by keeping select time field as a mandatory one. 通过将选择时间字段保持为强制字段来更好地验证用户输入字段。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM