Reputation: 27
I want to get a time difference from data using the TIMESTAMPDIFF
function, but this time i want to use a pure query builder in codeigniter
$this->db->select("TIMESTAMPDIFF(DAY, (".$this->db->select('payment_date')."), (".$this->db->select('download_date').")))",FALSE);
$query = $this->db->get('transaksi');
return $query;
I've tried the code above, but it shows an error like this :
Severity: 4096 Message: Object of class CI_DB_mysqli_driver could not be converted to string
and like this :
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '), ())) FROM
transaksi
' at line 1SELECT payment_date, download_date, TIMESTAMPDIFF(DAY, (), ())) FROM transaksi
is there any solution to get the data?
Upvotes: 1
Views: 252
Reputation: 26
Solution:
$this->db->select("payment_date, download_date, TIMESTAMPDIFF(DAY, payment_date, download_date)",FALSE);
$query = $this->db->get('transaksi');
return $query->result();
Upvotes: 1
Reputation: 1943
Sub Query not necessary there.
$this->db->select("payment_date, download_date, TIMESTAMPDIFF(DAY, payment_date, download_date)",FALSE);
$query = $this->db->get('transaksi');
return $query->result();
Upvotes: 1