gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:40:02 24 4
gpt4 key购买 nike

我无法插入 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com