I am trying the list the remining time on an auction listing. Below is the SQL query to gather the item data. There is a created and end time in the database, stored as datetime. At the end of the foreach, I get the current time from the system.
What I want is the difference between them, so that I can display the remaining time on the auction. I have tried a few ways, but can't seem to solve it. How do I do it?
$query = $this->db->query("SELECT * FROM tbl_auction_listing WHERE list_pk = $item LIMIT 1;");
foreach ($query->result() as $row)
{
$sellerid = $row->seller_fk;
$title = $row->title;
$description = $row->description;
$img_url = $row->image_url;
$category = $row->category_fk;
$starttime = $row->start_datetime;
$endtime = $row->end_datetime;
$startprice = $row->start_price;
$reserve = $row->reserve_price;
$buyprice = $row->bin_price;
$visits = $row->visits;
$now = date("Y-m-d H:i:s");
}
Note:
$remaining = $endtime->diff($now)->format("%m months, %d days, %H hours and %i minutes");
this line does not seem to work. It errors:
Fatal error: Call to a member function diff() on a non-object in controllers/listings.php on line 28