我想计算时差 我已经尝试过在mysql上进行查询和查询工作
SELECT *, CONCAT_WS(" ", date1, hour1) AS rhour1, CONCAT_WS(" ", date2, hour2) AS rhour2, (SELECT TIMEDIFF(rhour2,rhour1) AS diffhour) from TABLE1
我使用codeigniter查询生成器在活动记录中写入:
$this->db->select('*, CONCAT_WS(" ", date1, hour1) AS rhour1, CONCAT_WS(" ", date2, hour2) AS rhour2, (SELECT TIMEDIFF(rhour2,rhour1) AS diffhour)');
$this->db->from('table1');
$this->db->join('table2','table1.code_number = table2.code_number');
$query = $this->db->get();
结果我无法获得值差异小时:(
我的代码活动记录有什么问题?
希望这会对您有所帮助:
注意:确保您添加了所有列名的表名,就像这样table1.code_number
$this->db->select('*');
$this->db->select('CONCAT_WS(" ", date1, hour1) AS rhour1');
$this->db->select('CONCAT_WS(" ", date2, hour2) AS rhour2');
$this->db->select('TIMEDIFF(CONCAT_WS(" ", date2, hour2),CONCAT_WS(" ", date1, hour1)) AS diffhour');
$this->db->from('table1');
$this->db->join('table2','table1.code_number = table2.code_number');
$query = $this->db->get();