I have an issue.I need to calculate the time difference but here the date_create function is not showing any output in php.I am explaining my code below.
while($row=mysqli_fetch_assoc($orderqry)){
$exit_date=$row['delivered_datetime'];
if($exit_date!=='0000-00-00 00:00:00'){
$deldate=date_create($exit_date);
$today=date_create(date('Y-m-d H:i:s'));
echo $today;exit;
$interval = date_diff($deldate, $today);
$hours = $interval->format('%h');
}
}
Here i am trying to echo $today but its not giving any result.Here i need to calculate the time difference in hour.In my DB i have existing time in the format of date('Y-m-d H:i:s').Please help me.
$today->format('Y-m-d H:i:s');if you want to echo the resultecho $todaycause an error.echo $hours;it's ok. Please note that%hdoesn't return total hours, it return only values 0-23. To obtain total value you have to write$hours = $interval->h + ($interval->days*24);date_create()without parameter is same as creatingDateTimewith current date time. So$today=date_create(date('Y-m-d H:i:s'));will have same output as$today=date_create();