We have a website, that displays a list of regional offices with their opening and closing times. Part of the design requires that each office is styled to show if its is open or closed.

Our initial thoughts on how to handle this is as follows:

Get the current time {current_time format="%G%i"} so we have 2033

We then have custom fields for each entry, these are {office_open_time} and then {office_close_time} these times are set using GMT (the servers time) so lets take USA as an example 0900 in US time would be 1700 GMT, so the US times we set are:

{office_open_time} = 1700

{office_close_time} = 0100

Our template then checks the times:

{if "{current_time format="%G%i"}" <= "{office_close_time}" AND "{current_time format="%G%i"}" >= "{office_open_time}"}                         
we are open!                    
we are closed.                  

On the whole this works with a few exceptions and issues.

Again lets say our time here in GMT is 2033. The US opening time set in GMT is 1700 so thats correct, but the closing time is 0100 - so the current time is never less than the closing time..!

Then there's also the issue of the weekend but I think we can do that by returning the date as a day and checking if it equals "saturday" OR "sunday" - however I'm not sure how we decide 'when' that's valid... ie it's saturday in the uk before it's saturday in the us!

Any help or suggestions greatly appreciated

  • Could you ask a more specific question here?
    – UltraBob
    Commented Jan 25, 2013 at 9:14

3 Answers 3


via this dude on Facebook:

How about changing your american hours before you test them time (americantime) - (time difference) < opening_time sort of thing?

  • I think this is probably a neat solution though it may again require a simple plug-in to handle everything. Commented Jan 24, 2013 at 14:06
  • In VERY simplified terms, Essentially we can get the {countrytime} by setting the offset. Two examples would be the US is -0800 where as China its +0800 Next we'd take that from the current time to give us the time in that country.
    – paulcripps
    Commented Jan 24, 2013 at 20:43

A plugin isn't a bad route to take, I would also take a peek at Moment.js (http://momentjs.com/). They have a lot of "time functionality" built that you could probably harness.

  • I've bookemarked this - thank you but think we will end up going the plugin root.
    – paulcripps
    Commented Jan 24, 2013 at 20:39
  • If you have a couple of shops, then outputting all opening hours and compute with javascript might be a convenient route indeed.
    – GDmac
    Commented Jan 26, 2013 at 11:55

I would probably use a custom plugin. Feed the datetimes (and timezone?) into the plugin with parameters (or as tags), and do the checking, math and calculations with PHP inside the plugin. That also leaves you the option for editors to more easily and comfortably enter office hours in their own timezone.

  • Thanks GDmac, I think we're all saying the same that a plugin is the way forward here :)
    – paulcripps
    Commented Jan 24, 2013 at 20:38
  • maybe even go so far as a complete module. That way you can have custom entry fields as well.
    – GDmac
    Commented Jan 26, 2013 at 11:54

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.