public function getTotalActiveGroups()
{
return
$this->db->where('group_start >=', date('Y-m-d'))
->where('group_end <=', date('Y-m-d'))
->count_all_results('groups');
}
在我的管理页面中,我想显示活动的组。例如,在完成课程管理页面后,从2015年10月26日到2015年11月26日开始的组不应该显示哪个是不活跃的。在我的表有2个日期列"开始日期"answers"结束日期",这显示了多长时间的课程将运行。
public function getTotalActiveGroups()
{
return
$this->db->where('group_start <=', date('Y-m-d'))
->where('group_end >=', date('Y-m-d'))
->count_all_results('groups');
}
对于初学者来说答案足够棘手!!!!)))
试试这个
date_default_timezone_set("Asia/Kolkata"); //include your timezone
$time = date('Y-m-d h-i-s');
$query = $this->db->query("SELECT * FROM table_name WHERE end_date => '$time' ");
$result = $query->result_array();
return $result;
这将返回到现在为止只有活动的数据
如果你的group_start字段的类型是DATETIME(不是DATE),那么你需要使用MySQL函数DATE:
$this->db->where('DATE(group_start) >=', date('Y-m-d'))
->where('DATE(group_end) <=', date('Y-m-d'))
->count_all_results('groups');
你可以试试。
public function getTotalActiveGroups()
{
return
$this->db->where('DATE(group_start) >=', date('Y-m-d'))
->where('DATE(group_end) <=',date('Y-m-d',strtotime("+1 month")))
->count_all_results('groups');
}
我建议您在SQL查询中过滤日期:
SELECT *
FROM `tablename`
WHERE (enddate BETWEEN '2015-10-01' AND '2015-10-26')