Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Using SQL BETWEEN and AND together in DataObject::get

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 487 Views
  • novaweb
    Avatar
    Community Member
    111 Posts

    Using SQL BETWEEN and AND together in DataObject::get Link to this post

    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.

    487 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.