簡體   English   中英

想要使用php中的mysql查詢獲取最新日期

[英]want to get latest date using mysql queries in php

以下函數從多個日期返回最新日期

$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;

您可以使用sql函數MAX 示例SELECT MAX(date) FROM table;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM