如何以Codeigniter的方式编写数据库查询以在日期字段中搜索月份?
您能告诉我如何以 Codeigniter 的方式编写数据库查询以在日期字段中搜索月份吗?或者您能告诉我如何以 codeigniter 的方式编写以下查询吗?
提前致谢:)
"SELECT attendanceno FROM attendance WHERE (barcodeid = '$studentid') AND (month(attendancedate)='$month' AND year(attendancedate)='$year') ";
编辑
感谢 Stefan,他在下面回答了我的问题。阅读他的文章后,我还尝试了以下脚本并发现它有效。这就是为什么我只是想分享以防有人想使用它。但所有功劳都归功于斯特凡。 :)
$this->db->select('*');
$this->db->from('attendance');
$this->db->where('barcodeid', $studentid);
$this->db->where('month(attendancedate)', $month);
$this->db->where('year(attendancedate) ', $year);
$this->db->order_by('attendancedate ','ASC');
$getData = $this->db->get('', $perPage, $uri);
Could you please tell me how to write database query to search month in date field in Codeigniter's way? Or could you please show me how to write the following query in codeigniter's way?
Thanks in Advance :)
"SELECT attendanceno FROM attendance WHERE (barcodeid = '$studentid') AND (month(attendancedate)='$month' AND year(attendancedate)='$year') ";
Edit
Thanks to Stefan, who answered my question below. After reading his post I also tried the following script and found it working. That's why I just wanted to share in case anyone wants to use it. But all credit goes to Stefan. :)
$this->db->select('*');
$this->db->from('attendance');
$this->db->where('barcodeid', $studentid);
$this->db->where('month(attendancedate)', $month);
$this->db->where('year(attendancedate) ', $year);
$this->db->order_by('attendancedate ','ASC');
$getData = $this->db->get('', $perPage, $uri);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果日期和月份是字符串:
如果它们是整数
If date and month are strings:
if they are integers
假设:
Oracle 11 数据库
都将在 $month = 3 和 $year = 2017 时生成以下内容:
Assumptions:
Oracle 11 database
both will produce the following with $month = 3 and $year = 2017: