php - 19之后无法插入时间 :59:00 in mysql using php

标签 php mysql

我无法插入 20:00:00 或更早的时间值。它在时间为 00:00:00 到 19:59:00 时效果很好。我无法想象,因为它可以正常工作 19 小时。我是开发新手。我已经做了很多努力来弄清楚。但我做不到。请帮我。我在下面添加了 html、php 编码和 mysql“出勤”表。

 CREATE TABLE IF NOT EXISTS `attendance` (
    `id` int(11) NOT NULL,
      `shift_start_time` time NOT NULL,
      `empid` varchar(50) NOT NULL,
      `user` varchar(100) NOT NULL,
      `checkin` datetime(6) NOT NULL,
      `checkout` datetime NOT NULL,
      `worked_hours` time NOT NULL,
      `latehours` time NOT NULL,
      `late_seconds` int(11) NOT NULL,
      `Break1` time NOT NULL,
      `Break1out` time NOT NULL,
      `Break1hours` time NOT NULL,
      `Break2` time NOT NULL,
      `Break2out` time NOT NULL,
      `Break2hours` time NOT NULL,
      `Lunch_Break` time NOT NULL,
      `Lunch_Breakout` time NOT NULL,
      `Lunch_Breakhours` time NOT NULL,
      `A_Break` time NOT NULL,
      `A_Breakout` time NOT NULL,
      `A_Breakhours` time NOT NULL,
      `A_BreakReason` varchar(1000) NOT NULL,
      `totalbreak` time NOT NULL,
      `workhrs` time NOT NULL,
      `meeting_hours` time NOT NULL,
      `checkindate` date NOT NULL
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=350 ;




<form action="checkincheckout.php" method="post"><table><tr><td><label  for="line_items"                                                                    >
                                                                  <p class="text-info">Check In</p>
                                                                  </label><input type="radio" class="form-control" placeholder="Enter Project Name" name="checkin" value="<?php 
                                                                                                echo date('Y-m-d H:i:s');?> " >
    </td><td><label  for="line_items"                                                                    >
                                                                  <p class="text-info">Check Out</p>
                                                                  </label><input type="radio" class="form-control" placeholder="Enter Project Name" name="checkout" value="<?php echo date('Y-m-d H:i:s');?>"></td></tr><tr><td colspan="2"><input type="Submit" class="btn btn-primary" value="Submit" name="submit" >


    </script></td></tr></table></form>

//checkingcheckout.php

     if(isset($_POST['checkin']))
        {
            //$checkin =date("Y-m-d H:i:s", $_POST['checkin']);
                 $checkin = $_POST['checkin'];
                 $checkindate=substr('$checkin',0,10);

                 if($checkin>$_SESSION['START_TIME'])
                 {
                    $timeDiff=strtotime($checkin)-strtotime($_SESSION['START_TIME']);



    $init = $timeDiff;
    $hours = floor($init / 3600);
    $minutes = floor(($init / 60) % 60);
    $seconds = $init % 60;

    echo "$hours:$minutes:$seconds";
    $ela=$hours.'+'.$minutes.'+'.$seconds;

                      $sql = mysql_query("INSERT INTO `attendance`(shift_start_time,empid,user,checkin,latehours,late_seconds,checkindate) VALUES ('".$_SESSION['START_TIME']."','".$_SESSION['USERNAME']."','".$_SESSION['NAME']."','$checkin','$ela','$timeDiff','$checkindate')"); 
                 }

最佳答案

在我们插入表之前,php 时间应该转换为我的 sql 兼容时间格式。您可以为此使用以下代码

$date = DateTime::createFromFormat( 'H:i A', $php_time);
$sql_time = $date->format( 'H:i:s');
  • $php_time - php 中的时间格式

  • $sql_time - mysql 中的时间格式

关于php - 19之后无法插入时间 :59:00 in mysql using php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31377959/

相关文章:

mysql - 如何通过百分比计算获得投票结果

php - 尝试获取行数时 PDO 上的 fetchColumn 错误

php - 如何获取两个子串之间的子串?

php - Perl 与 PHP 的网络抓取

javascript - json_decode 返回 NULL 和有效的 json

php - 这个 cronjob 会工作吗?

mysql - Bash 脚本 Mysql 警告 : Using a password on the command line interface can be insecure

php - SOAP 错误 : Encoding: Object has no property

PHP:字符串在外部文件中不起作用

php - 如何使用 CakePHP3 定义多对多关系?