Skip to main content
improved formatting
Source Link
artmem
  • 1k
  • 9
  • 18

I have an events channel where each entry has three custom date/time fields:

startDate -- Date(Date Only startTime)

startTime -- Time(Time Only endTime)

endTime -- Time(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?

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?

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?

Source Link
artmem
  • 1k
  • 9
  • 18

Order entries by custom date and time fields

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?