[英]Using timestampdiff with query builder codeigniter
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 我想使用TIMESTAMPDIFF
函数从数据中获取时差,但是这次我想在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 严重性:4096消息:无法将类CI_DB_mysqli_driver的对象转换为字符串
and like this : 像这样:
You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MariaDB server version for the right syntax to use near '), ())) FROM
transaksi
' at line 1 检查与您的MariaDB服务器版本相对应的手册,以在第1行的'),()))FROMtransaksi
'附近使用正确的语法SELECT payment_date, download_date, TIMESTAMPDIFF(DAY, (), ())) FROM transaksi 从transaksi中选择付款日期,下载日期,TIMESTAMPDIFF(DAY,(),()))
is there any solution to get the data? 有什么解决方案来获取数据吗?
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();
Solution: 解:
$this->db->select("payment_date, download_date, TIMESTAMPDIFF(DAY, payment_date, download_date)",FALSE);
$query = $this->db->get('transaksi');
return $query->result();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.