查询 838:59:59 中的 MySQL 时间值? [英] MySQL time value in query 838:59:59?
问题描述
我想问一下.
我正在尝试将 TIME 值添加到 mysql 数据库中.但是添加到数据库中的值是 838:59:59
I'm trying to add TIME value into mysql database .But the value added in database is 838:59:59
并且它仅以 838:59:59 的形式存储到 timein 列中.超时列结果为 00:00:00 值.
And it only store into timein column as 838:59:59. Timeout column result is 00:00:00 value.
代码如下
<?php
$connect = mysqli_connect("localhost", "root", "root", "database");
global $connect;
if(isset($_POST['Submit']))
{
$timeout = strtotime('08:30:00');
$timein = strtotime('12:30:00');
$time_out_user = strtotime($_POST['timeout']);
$time_in_user = strtotime($_POST['timein']);
if(($time_out_user >= $timeout) && ($time_out_user <= $timein))
{
echo "Duplicate time";
}
else
{
$add = "INSERT INTO table (timeout,timein)
VALUES ('$time_out_user','$time_in_user')";
$addDateTime = mysqli_query($connect,$add);
echo "Time added";
}
}
?>
<form action="test.php" method="post">
<table>
<tr>
<td><i class="fa fa-unlock-alt"></i> </td>
<td>Time Out: </td>
<td><input type ="time" name="timeout" size="30"></td>
</tr>
<tr>
<td><i class="fa fa-unlock-alt"></i> </td>
<td>Time In: </td>
<td><input type ="time" name="timein" size="30"></td>
</tr>
</table>
<p><input class="btnSuccess" type ="submit" name="Submit" value="Submit"> </p>
</form>
谢谢.
推荐答案
答案很简单,就是该字段可以容纳的最大值.
The answer is simply, it's the maximum that field can hold.
MySQL 以HH:MM:SS"格式(或'HHH:MM:SS' 格式用于大小时值).TIME 值的范围可以从-838:59:59"到838:59:59".小时部分可能如此之大,因为TIME 类型不仅可以用来表示一天中的某个时间(它必须少于 24 小时),但也包括经过的时间或时间间隔两个事件之间(可能远大于 24 小时,甚至阴性).
MySQL retrieves and displays TIME values in 'HH:MM:SS' format (or 'HHH:MM:SS' format for large hours values). TIME values may range from '-838:59:59' to '838:59:59'. The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).
您最好只使用 int 字段(其中值存储为与开始时间的秒差).通常的做法是使用一个字段来存储自纪元以来经过的秒数,而不是日期时间字段.否则,您需要切换到 datetime 字段.
You would probably be better off just using an int field (where the value is stored as seconds difference from the starting time). It's a common practice to have a field that stores seconds elapsed since epoch rather than a datetime field anyway. Else you would need to switch to a datetime field.
http://dev.mysql.com/doc/refman/5.7/en/time.html
这篇关于查询 838:59:59 中的 MySQL 时间值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!