Body: <p>I would like to order my entries first by date, and then by time. So if several entries are on the same date, they will be ordered by time within that day.</p>
  <p>This is my query:</p>
  <pre><code>{% set query = {
      section: 'agenda',
      dateBegin: '&gt;= ' ~ todayMidnight,
      limit: null,
      orderBy: 'dateBegin ASC, timeBegin ASC'
  }%}
  </code></pre>
  <p>&quot;dateBegin&quot; is a date field with only the date visible<br />
  &quot;timeBegin&quot; is a date field with only the time visible</p>
  <p>This code does not work.</p>
  <p>For instance it will order times the following way:</p>
  <p>Same Day event:<br />
  10:00 – 17:00<br />
  15:00 – 16:00<br />
  11:00 – 13:00<br />
  12:00 – 13:30</p>
  <p>I've tried <code>orderBy: 'dateBegin ASC, timeBegin|date(&quot;H:i&quot;) ASC'</code>, but it generates an error 500:</p>
  <p>Any idea on how to achieve this natively?</p>
  <p>Thanks in advance</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-07-05T17:20:48.577Z
Comments.Text: Forgive my obvious question but it should at least be addressed I think: do you definitely need to use separate fields for date and time? If you use a single combined date + time field this would just solve itself automatically, and you'd also have a cleaner content model.
Comments.UserDisplayName: James Smith
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-23T01:48:11.443Z
Comments.Text: Commenting to add that on date fields in Craft v3 + v4 there is a toggle to enable times as well. If you turn that on it will give you the same options that the Time field has for increments etc.
Comments.UserDisplayName: cherrykoda
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-24T16:50:16.850Z
Comments.Text: Hi, thanks for your responses. In my case I need two different fields for the date and the time. It should be possible to order them like I want?
Comments.UserDisplayName: outline4
Tags: <ordering><order>
Title: How to order entries by two fields, one being a date, the other being a time?
ThreadText: # How to order entries by two fields, one being a date, the other being a time?
  
  (Asked by: username_0 on 2023-07-04)
  
  I would like to order my entries first by date, and then by time. So if several entries are on the same date, they will be ordered by time within that day.
  
  This is my query:
  
  ```
  {% set query = {
      section: 'agenda',
      dateBegin: '>= ' ~ todayMidnight,
      limit: null,
      orderBy: 'dateBegin ASC, timeBegin ASC'
  }%}
  
  ```
  
  "dateBegin" is a date field with only the date visible  
  "timeBegin" is a date field with only the time visible
  
  This code does not work.
  
  For instance it will order times the following way:
  
  Same Day event:  
  10:00 – 17:00  
  15:00 – 16:00  
  11:00 – 13:00  
  12:00 – 13:30
  
  I've tried `orderBy: 'dateBegin ASC, timeBegin|date("H:i") ASC'`, but it generates an error 500:
  
  Any idea on how to achieve this natively?
  
  Thanks in advance
  
  **Tags:** ordering, order
  
  > **Comments:**
  > **username_1**: Forgive my obvious question but it should at least be addressed I think: do you definitely need to use separate fields for date and time? If you use a single combined date + time field this would just solve itself automatically, and you'd also have a cleaner content model.  
  > **username_2**: Commenting to add that on date fields in Craft v3 + v4 there is a toggle to enable times as well. If you turn that on it will give you the same options that the Time field has for increments etc.  
  > **username_0**: Hi, thanks for your responses. In my case I need two different fields for the date and the time. It should be possible to order them like I want?  
  
  ---
  
  ## 0 answers
  
  