<?php
session_start();
@mysql_connect('localhost','jk','') or die('Please Check Username or Password');
@mysql_select_db('jks') or die('error connetcing database');
$qry3="Select ID from fresh_orders";
$id=mysql_query($qry3);
$qry1="Select CurDate from fresh_orders";
$rs=mysql_query($qry1);
$row=mysql_fetch_array($rs);
$d210=$row[0];
$d21=date("Y-m-d", strtotime($d210));
echo (" d21 = "),$d21;
$qry2="Select DueDate from fresh_orders";
$rss=mysql_query($qry2);
$row=mysql_fetch_array($rss);
$d71=$row[0];
$d7=date("Y-m-d", strtotime($d71));
echo (" d7 = "),$d7;
$date1=date_create("$d21");
$date2=date_create("$d7");
$interval=date_diff($date1,$date2);
echo $interval->format("%R%a days");
$qry="update fresh_orders set DDays='".$interval."' where ID=".$id."";
mysql_query($qry);
echo $qry;
?>
Output is as follows:
d21 = 2016-07-20 d7 = 2016-07-10 days = -10 days
( ! ) Catchable fatal error: Object of class DateInterval could not be converted to string
It does calculate the difference properly but can't update in database! Gives the Fatal error when trying to update in database. Pls Help !
Thanks In Advance