How to validate a datetime with date in a php and mysql query?

0

I want to validate the entries and exits of a number of people in the day, that is, count how many people have entered, how many have left. for this I have a field called fecha_entrada and fecha_salida (both fields are datetime), the idea as I mentioned is to validate how many have entered and left in the day but I specifically need the date (Ymd) without setting the time:

CODE:

$cant_peoples = 
  $this->db->select('count(*) as in_company')
  ->from('company')
  ->where('entry_date', date('Y-m-d'))
  ->where('entry_date !=', '' )
  ->get()
  ->row();
  

The problem is that this internally throws a 0, and I do not know if   it is because it is not possible to validate a date with datetime

    
asked by JDavid 17.12.2018 в 06:00
source

1 answer

1

It is possible to compare DATE with DATETIME, but the condition will never be met. The query return will always be NULL. This would be the query:

$this->db->select('count(*) as in_company');
$this->db->from('company');
$this->db->where('DATE(entry_date)',  date('Y-m-d'));
$this->db->where('entry_date !=', '' );
$query = $this->db->get();
$res= $query->result();
    
answered by 17.12.2018 / 10:06
source