I have been trying to find answer for my problem, unable to find one, Pl find below code where it works fine if the input date for $start is given. But when the same is done using a date field without time, it gives an error.
<?php
$start = new DateTime('2011-10-12');
$today = new DateTime();
$days = round(abs($today->format('U') - $start->format('U')) / (60*60*24));
echo $days;
?>
It echos 146.
But if I replace the $start with a table field like:
$start = $demurage2[DC_date];
echo $start;
$today = new DateTime();
$dcdate = round(abs($today->format('U') - $start->format('U')) / (60*60*24));
echo $dcdate;
Error:
Fatal error: Call to a member function format() on a non-object in /home/tech17/public_html/svga/invoice-detail.php on line 490
I have tried echo only $start, it shows the correct date from the table: 2012-01-17.
Your $start is not an object of DateTime class in the second example, so of course it does not work. How is the date stored? Technically this might work, but it is highly dependent on what this $demurage2[‘DC_date’] value is.