我想检查两个日期是否相等,它的$query_array['datepicker']
和absensi_tanggal
。他们有不同的格式,所以我CONVERT
的absensi_tanggal
.
SQL 会自动转换日期吗?我试图不转换它,但查询不起作用,它总是返回 0 行。
所以我尝试了这段代码,但它不起作用。
$q = $this->db->select('*', 'CONVERT(VARCHAR(10), absensi_tanggal, 101) AS temp')->from('msabsensi')->limit($limit, $offset)
->join('msumat', 'msabsensi.umat_id = msumat.umat_id')
->join('mskelas', 'mskelas.kelas_id = msumat.kelas_id');
$q->where('CONVERT(VARCHAR(10), absensi_tanggal, 101)', $query_array['datepicker']);
$result['rows'] = $q->get()->result();
这是我得到的错误(我认为CONVERT AS
我所做的select()
不起作用):
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(10), absensi_tanggal, 101) '04/01/2013' LIMIT 10' at line 5
SELECT * FROM (`msabsensi`) JOIN `msumat` ON `msabsensi`.`umat_id` = `msumat`.`umat_id` JOIN `mskelas` ON `mskelas`.`kelas_id` = `msumat`.`kelas_id` WHERE CONVERT(VARCHAR(10), absensi_tanggal, 101) '04/01/2013' LIMIT 10
Filename: C:\xampp\htdocs\ci_gabdb\system\database\DB_driver.php
Line Number: 330
任何帮助表示赞赏,谢谢:D