<p>You'll want to change that <code>startTime</code> to <code>field_startTime</code>.</p>

<p>Anything in the <code>orderBy</code> gets passed directly onto SQL and Craft is smart enough to do the replacement for <code>startDate</code> behind the scenes, but columns in methods (like <code>time()</code>) or aggregate functions need to be manually prefixed.  This should work:</p>

<pre><code>{% set allEntries = craft.entries.section('sparkSchedule').limit(null).orderBy('startDate asc, time(field_startTime)').all() %}
</code></pre>

CC BY-SA 4.0
2019-07-08T21:34:35.183Z
This seemed to be working fine using the code in the posted solution, but now, it's suddenly ignoring the custom time, seemingly in favor of the entry post time. Has something changed with Craft?
artmem
CC BY-SA 4.0
2019-02-16T00:17:37.157Z
2019-02-16T00:17:37.157Z
Brad Bell
<p>I have an events channel where each entry has three custom date/time fields:</p>

<p>startDate (Date Only)</p>

<p>startTime (Time Only)</p>

<p>endTime (Time Only)</p>

<p>I was originally using this code to set my entries, but it causes problems if they aren't all entered on the same day:</p>

<pre><code>{% set allEntries = craft.entries.section('sparkSchedule').limit(null).orderBy('startDate asc').all() %}
</code></pre>

<p>I've seen answers from Craft 2 saying that i could use time(startTime) to sort by just the time portion of my startTime field:</p>

<pre><code>{% set allEntries = craft.entries.section('sparkSchedule').limit(null).orderBy('startDate asc, time(startTime)').all() %}
</code></pre>

<p>but when I do that, i get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'startTime' in 'order clause'</p>

<p>Am I doing something wrong?</p>

CC BY-SA 4.0
2019-02-14T02:38:21.007Z
Why are you separating startDate and startTime into two different fields, rather than enabling "time" on the date field?
Roi Agneta
CC BY-SA 4.0
2019-02-14T15:15:59.973Z
Client preference
artmem
<craft3><datetime><ordering>
Order entries by custom date and time fields
# Order entries by custom date and time fields

(Asked by: username_0 on 2019-02-13)

I have an events channel where each entry has three custom date/time fields:
startDate (Date Only)
startTime (Time Only)
endTime (Time Only)
I was originally using this code to set my entries, but it causes problems if they aren't all entered on the same day:
{% set allEntries = craft.entries.section('sparkSchedule').limit(null).orderBy('startDate asc').all() %}

I've seen answers from Craft 2 saying that i could use time(startTime) to sort by just the time portion of my startTime field:
{% set allEntries = craft.entries.section('sparkSchedule').limit(null).orderBy('startDate asc, time(startTime)').all() %}

but when I do that, i get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'startTime' in 'order clause'
Am I doing something wrong?

**Tags:** craft3, datetime, ordering
> **Comments:**
> **username_1**: Why are you separating startDate and startTime into two different fields, rather than enabling "time" on the date field?  
> **username_0**: Client preference  

---

## 1 answers

### Answer by username_2 on 2019-02-16. Score: 3 | Accepted answer

You'll want to change that startTime to field_startTime.
Anything in the orderBy gets passed directly onto SQL and Craft is smart enough to do the replacement for startDate behind the scenes, but columns in methods (like time()) or aggregate functions need to be manually prefixed.  This should work:
{% set allEntries = craft.entries.section('sparkSchedule').limit(null).orderBy('startDate asc, time(field_startTime)').all() %}

> **Comments:**
> **username_0**: This seemed to be working fine using the code in the posted solution, but now, it's suddenly ignoring the custom time, seemingly in favor of the entry post time. Has something changed with Craft?  

---

