I'm trying to show content based on the day and time of day. Specifically, the site I'm working on offers a live-stream every Sunday from 9:45 - 1:45 and we want to feature the live-stream on the homepage while it is live.

I have created a channel called "featured" which has an entry called Sunday. Using the following code, I can show the Sunday entry on Sunday.

To display the entry at a particular time, I created a Start Time and End Time field. Using that, I can display what I need to during the specified time.

The problem is that the entry has to be updated weekly to have the correct date. Is there a way to use start_time and end_time without a date? Or, every Sunday? Or, only Sunday?

    {exp:channel:entries channel="featured" url_title='{current_time format="%l"}'}
    {if current_time > start_time && current_time < end_time}
      <img src="{live-stream-image}">
    <img src="{standard-image">

As I said, this works but I'd like to not have to touch the entry each week to update the date. I'm not opposed to some other workflow, PHP, etc.

Thanks for any advice.

  • Are your start_time and end_time fields standard date field are are they text based? I'm wondering if you can set your conditional to check based on time: i.e., if your custom fields are date fields; {if "{current_time format='%h%i'}" >= "{start_time format='%h%i'}"} If your fields are text based you can probably match up the conditional by formatting current time into a comparable value.
    – pixldev
    Commented Feb 15, 2017 at 2:22
  • They are standard date fields. I'll give this a try. Thanks! Commented Feb 15, 2017 at 11:38
  • 1
    Why do you need the fields? Why not just write a query in your template to 1-check its sunday, 2-check it matches the time slot, and if true display entry by entry ID? Yes it is hard coded and not search - but if the entry does not change, that should be no issue Commented Feb 17, 2017 at 11:49
  • @Nevsie-Modeten that's a good suggestion. I didn't know how to write a query like that. What would it look like? Commented Feb 17, 2017 at 14:52
  • Just exactly the same as your doing. Except instead of comparing two variables, your comparing it to a fixed value string or number. And then joining it with a && or AND. Commented Feb 18, 2017 at 16:31

1 Answer 1


Thanks to @Nevsie-Modeten, I reworked the query to the following:

{if {current_time format='%w'} == 0 &&
    {current_time format='%G%i'} >= 930 &&
    {current_time format='%G%i'} <= 1230
    Content to be displayed during this time.
    Content to be displayed during other times.

This checks the day and time and displays content appropriately. Using this method, I was able to eliminate the start_time and end_time channel fields that I created.

Thanks for taking the time to look and providing input!

  • Just a note that since you're using numeric comparisons, double-quoted strings are not necessary. Also you can use whitespace to make it more legible; I went ahead and edited your solution for those changes. :) Commented Mar 14, 2017 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.