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


i ask .

i'm trying add time value mysql database .but value added in database 838:59:59

and store timein column 838:59:59. timeout column result 00:00:00 value.

the code 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 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.

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

mysql retrieves , displays time values in 'hh:mm:ss' format (or 'hhh:mm:ss' format large hours values). time values may range '-838:59:59' '838:59:59'. hours part may large because time type can used not represent time of day (which must less 24 hours), elapsed time or time interval between 2 events (which may greater 24 hours, or negative).

you better off using int field (where value stored seconds difference starting time). it's common practice have field stores seconds elapsed since epoch rather datetime field anyway. else need switch datetime field.

http://dev.mysql.com/doc/refman/5.7/en/time.html


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -