I wanna save and store date format from $interval in database column which have dattime type. But its not work, in database not show that value.
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')")
;}
Try this
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."')")
;}
The $interval
value is a string. If you want to store the data in that format then you should change the data type of your approval column from your sla table into varchar instead of datetime.
Try this:
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')")
;}