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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Using SQL BETWEEN and AND together in DataObject::get

Go to End



Community Member, 116 Posts

13 January 2012 at 9:04am


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.