I want to check if two dates are equal, its $query_array['datepicker']
and absensi_tanggal
. They have the different format, so i CONVERT
the absensi_tanggal
.
Do SQL automatically convert the date? i tried not to convert it, but the query is not working, it always return 0 row.
So i tried this code, but its not working.
$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();
This is the error i got (i think the CONVERT AS
that i did in select()
is not working) :
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
Any help is appreciated, Thanks :D