Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

Using SQL BETWEEN and AND together in DataObject::get


Reply

520 Views

Avatar
novaweb

13 January 2012 at 9:04am Community Member, 115 Posts

Greets,

I am trying to return "Appointment" DataObjects in the morning in one function, and then in the afternoon in another. It's throwing an error due to the double "and"'s in the statement. I have never used BETWEEN before in SS.

DataTypes being used are Date and Time.

   function getMorningAppointments() {
      $today = date('Y-m-d');
      $appointments = DataObject::get("Appointment", "`Date` = '{$today}' AND `Time` BETWEEN '07:00:00' AND '11:59:59'");
      return $appointments;
   }
   
   function getAfternoonAppointments() {
      $today = date('Y-m-d');
      $appointments = DataObject::get("Appointment", "`Date` = '{$today}' AND `Time` BETWEEN '12:00:00' AND '23:59:59'");
      return $appointments;
   }

Any pointers greatly appreciated.