Answers.Body: <p>Having done some further testing and research I believe this is a case of having to merge two date objects and ensuring that these are set as date/time objects when merging them into a variable.</p>
  <p>Here are some examples way:</p>
  <pre><code>
  {% set thisWeeksDayAndTime = thisWeeksDay|date() ~ ' ' ~ classStartTime|time() %}
  
  {% set thisWeeksDay = page.startDate|date_modify('this  ' ~ classDay ~ ' ' ~  classStartTime|time()) %}
  
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-09T10:30:00.833Z
Answers.LastActivityDate: 2020-07-09T10:30:00.833Z
Answers.UserDisplayName: Terry Upton
Body: <p>I am trying to generate a modified date and time from a combination of content fields and the current date but I am getting stuck and keep hitting errors, so my logic is either not correct or  I am approaching this all wrong. Here is an explanation with some examples of what I am trying to achieve.</p>
  <p>So I want to check if a child that is registered to a class (A class occurs on a specific day/time each week) that they only get to see a page if the date and time of their class is now in the past. As an example, a child is on a class Tuesday 4.15pm - 5.15pm - I want to ensure they only get to see the page at 4.15pm.</p>
  <p>In the CMS I have a select list for the day, and related entries for the time slots, but these use standard time fields.</p>
  <p>Here is how I have tried to approach it.</p>
  <pre><code>###First Generate a Modified Date based on the their class day. This will check if Tuesday is this week or next week. Like so:
  
  #Get the class day for the child
  {% set classDay = child.tuitionClass[0].weekday.label %}
  
  #Set the next occurring date for the class day
  {% set nextClass = now | date_modify('this ' ~ classDay) %}
  </code></pre>
  <p>This is fine so far and gives me a date to work with. I can compare today's date against the next class date to see if it has passed.</p>
  <p>The part I am stuck on is the time aspect. I cannot figure out how to generate the modified_date with the class time so I can do the comparison on one object rather than two.</p>
  <pre><code>#Get the class time
  {% set classStartTime = child.tuitionClass[0].classTime[0].startTime %}
  </code></pre>
  <p>How can I merge the class time with the modified date so that the nextClass is set to the date AND time of the nextClass. With the logic earlier it sets the time to default to 12:00 - the start of the day.</p>
  <p>Everything I try I either hit an error <code>Object of class DateTime could not be converted to string</code>.</p>
  <p>I could perhaps as suggested do the logic in two parts. First compare the date and then compare the time. But I was hoping for a single comparison.</p>
  <p>Is anyone able to help out with this final part of the logic?</p>
  <p>Thanks in advance.</p>
  
Tags: <templating><datetime><logic>
Title: How can I merge a Modified Date and Time in Twig?
ThreadText: # How can I merge a Modified Date and Time in Twig?
  
  (Asked by: username_0 on 2020-07-09)
  
  I am trying to generate a modified date and time from a combination of content fields and the current date but I am getting stuck and keep hitting errors, so my logic is either not correct or I am approaching this all wrong. Here is an explanation with some examples of what I am trying to achieve.
  
  So I want to check if a child that is registered to a class (A class occurs on a specific day/time each week) that they only get to see a page if the date and time of their class is now in the past. As an example, a child is on a class Tuesday 4.15pm - 5.15pm - I want to ensure they only get to see the page at 4.15pm.
  
  In the CMS I have a select list for the day, and related entries for the time slots, but these use standard time fields.
  
  Here is how I have tried to approach it.
  
  ```
  ###First Generate a Modified Date based on the their class day. This will check if Tuesday is this week or next week. Like so:
  
  #Get the class day for the child
  {% set classDay = child.tuitionClass[0].weekday.label %}
  
  #Set the next occurring date for the class day
  {% set nextClass = now | date_modify('this ' ~ classDay) %}
  
  ```
  
  This is fine so far and gives me a date to work with. I can compare today's date against the next class date to see if it has passed.
  
  The part I am stuck on is the time aspect. I cannot figure out how to generate the modified\_date with the class time so I can do the comparison on one object rather than two.
  
  ```
  #Get the class time
  {% set classStartTime = child.tuitionClass[0].classTime[0].startTime %}
  
  ```
  
  How can I merge the class time with the modified date so that the nextClass is set to the date AND time of the nextClass. With the logic earlier it sets the time to default to 12:00 - the start of the day.
  
  Everything I try I either hit an error `Object of class DateTime could not be converted to string`.
  
  I could perhaps as suggested do the logic in two parts. First compare the date and then compare the time. But I was hoping for a single comparison.
  
  Is anyone able to help out with this final part of the logic?
  
  Thanks in advance.
  
  **Tags:** templating, datetime, logic
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-07-09. Score: 1 | Accepted answer
  
  Having done some further testing and research I believe this is a case of having to merge two date objects and ensuring that these are set as date/time objects when merging them into a variable.
  
  Here are some examples way:
  
  ```
  
  {% set thisWeeksDayAndTime = thisWeeksDay|date() ~ ' ' ~ classStartTime|time() %}
  
  {% set thisWeeksDay = page.startDate|date_modify('this  ' ~ classDay ~ ' ' ~  classStartTime|time()) %}
  
  ```
  
  
  ---
  
  