【发布时间】:2018-04-02 11:14:03
【问题描述】:
以下函数返回多个日期的最新日期
$userid = $this->session->userdata['userId'];
$type="meeting";
$currentdate = date("Y-m-d H:i:s");
$this->db->select('DATE(date) as date');
$this->db->from('tbl_meetings');
//if user is admin want the latest date from all dates in the respected table
if($userid!='1') {
$where = "tbl_meetings.date >=".$currentdate. "AND tbl_inbox.type='meeting'";
$this->db->join('tbl_inbox as t2', 't2.meetingid = tbl_meetings.id','left');
// the following query to get latest date from all dates which that per ticular user(not admin) allocated meetings
} else {
$this->db->where('date >', $currentdate);
}
$this->db->order_by('ABS(DATEDIFF(date, NOW()))', 'ASC');
$this->db->limit(1);
$query = $this->db->get();
$result=$query->result();
return $result;
【问题讨论】:
-
这里有什么问题?
-
ORDER BY ABS(DATEDIFF(date, NOW())) ASC LIMIT 1返回最接近现在的日期。这与多个日期中的最新日期不同。