我想在数据库列中保存并存储来自$ interval的日期格式,它具有数据时间类型。但它不起作用,在数据库中没有显示出价值。
if ($no > 1){
$startdate = new DateTime($lup[$no]);
$enddate = new DateTime($lup[$no-1]);
$int = $startdate->diff($enddate);
$interval = $int->format("%d days, %h hours, %i minutes, and %s seconds ");
echo "<td>".$interval." </td>";
}else
{
echo "<td> --- </td> ";
}
if ($data['id'] == 2){
$sql = mysql_query("
INSERT INTO sla (booking_id, approval)
VALUES ('$booking_id[$no]', '$interval')")
;}
答案 0 :(得分:1)
试试这个:
if ($no > 1){
$startdate = new DateTime($lup[$no]);
$enddate = new DateTime($lup[$no-1]);
$int = $startdate->diff($enddate);
$interval = $int->format("%d days, %h hours, %i minutes, and %s seconds ");
$dtInterval = $int->format('Y-m-d H:i:s');
echo "<td>".$interval." </td>";
}else
{
echo "<td> --- </td> ";
}
if ($data['id'] == 2){
$sql = mysql_query("
INSERT INTO sla (booking_id, approval)
VALUES ('$booking_id[$no]', '$dtInterval')")
;}
答案 1 :(得分:0)
试试这个
if ($no > 1){
$startdate = new DateTime($lup[$no]);
$enddate = new DateTime($lup[$no-1]);
$int = $startdate->diff($enddate);
$interval = $int->format("%d days, %h hours, %i minutes, and %s seconds ");
echo "<td>".$interval." </td>";
}else
{
echo "<td> --- </td> ";
}
if ($data['id'] == 2){
$sql = mysql_query("
INSERT INTO sla (booking_id, approval)
VALUES ('".$booking_id[$no]."', '".$interval."')")
;}
答案 2 :(得分:0)
$interval
值是一个字符串。如果您希望以该格式存储数据,则应将审核列的数据类型从 sla 表更改为 varchar ,而不是的日期时间强>