Salvatore Fucito
Salvatore Fucito

Reputation: 355

How to select a date less than the current one?

I want to load the appointment history of my customer from db, each record have the start_datetime and end_datetime, actually my query looks like this:

$query = $this->db
        ->select('*')
        ->from('appointments')
        ->where('id', 5) 'id of record to select
        ->where('start_datetime' ) 'here's indecision
        ->get()->result_array();

essentially the record to load should be all record previoulsly of current datetime. How I can pass this condition in the where clause?

Upvotes: 2

Views: 107

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38672

Try this

$now = date('Y-m-d H:i:s'); # get current time stamp
$query = $this->db
        ->select('*')
        ->from('appointments')
        ->where('id', 5)
        ->where(start_datetime <= $now ) # Sometimes date($now)
        ->get()->result_array();

Upvotes: 2

Related Questions