ivva
ivva

Reputation: 2949

Select query with Date of Today not working

I'm trying to select from table Documents where Date is Today's date. I'm using Codeigniter. But it shows only these documents where there isn't hour. I mean where in database date is: 2015-06-25 00:00:00. But it doesn't display these documents where there is an hour - for example : 2015-06-25 08:34:00. How to display all documents where Date is current date , no matter what is the hour.

<?php
 $date = new DateTime("now");
 
 $curr_date = $date->format('Y-m-d ');

 $this->db->select('*');
 $this->db->from('documents'); 
 $this->db->where('Date', $curr_date);
 $query = $this->db->get();
    return $query->result();

Upvotes: 3

Views: 20394

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

Try this

<?php
 $date = new DateTime("now");

 $curr_date = $date->format('Y-m-d ');

 $this->db->select('*');
 $this->db->from('documents'); 
 $this->db->where('DATE(Date)',$curr_date);//use date function
 $query = $this->db->get();
    return $query->result();

MySQL date Function

Upvotes: 13

Related Questions