Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

php - MySQL time value in query 838:59:59?

i would like to ask .

I'm trying to add TIME value into mysql database .But the value added in database is 838:59:59

And it only store into timein column as 838:59:59. Timeout column result is 00:00:00 value.

The code as below

<?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>

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The answer is simply, it's the maximum that field can hold.

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).

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...