gpt4 book ai didi

php - 想要在 php 中使用 mysql 查询获取最新日期

转载 作者:行者123 更新时间:2023-11-29 06:45:37 31 4
gpt4 key购买 nike

以下函数返回多个日期中的最新日期

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

关于php - 想要在 php 中使用 mysql 查询获取最新日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49610194/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com