skip to Main Content

SELECT * FROM tbl_booking WHERE ‘2023-10-27 13:00:00’ between
startDate and endDate

I need to write the query in code igniter how it can be done

2

Answers


  1. You can do it like this

    $this->db->select('*');
    $this->db->from('tbl_booking');
    $this->db->where('2023-10-27 13:00:00 BETWEEN startDate AND endDate');
    $query = $this->db->get();
    
    
    Login or Signup to reply.
  2. you can customize the where just by:

    $builder = $db->table('tbl_booking');
    $builder->where("'2023-10-27 13:00:00' BETWEEN startDate AND endDate");
    $query = $builder->get();
    
    // Produces: SELECT * FROM tbl_booking WHERE '2023-10-27 13:00:00' between startDate and endDate
    

    And if you prefer, you can do the escape way too:

    $time = '2023-10-27 13:00:00';
    $builder->where("{$time} BETWEEN startDate AND endDate");
    

    here is an online example of the query.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search