S.A.
S.A.

Reputation: 57

want to get latest date using mysql queries in php

following function return latest date from multiple dates

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

Upvotes: 0

Views: 211

Answers (1)

Grulex
Grulex

Reputation: 175

You can use sql function MAX. Example - SELECT MAX(date) FROM table;

Upvotes: 2

Related Questions