• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Is this possible with a <Xen IF>? Message displayed based on day

DaveL

Well-known member
#1
Is there an <if> command I could use to have different text displayed depending on the day of the week?

Eg:

<if Monday>
Hello its Monday </if>
<if Tuesday>
Hello its Tuesday</if>

If that is possible, Is it possible to break it down even further, is there an <if> command for time of day?

Eg:
<if 0800-1100>
Good Morning!</if>
<if 1100-1300>
Its Lunchtime!</if>

I used something similar many years ago n vbulletin, however it was built into a skin I purchased so cant go back and look at the code.

Fingers crossed it will be possible!

Dave
 

Jake Bunce

XenForo moderator
Staff member
#4
Hours of the day (specify the range in 24 hour format, in this example between 8:00 and 20:00):

Code:
<xen:if is="{xen:time $serverTime, 'G'} >= 8 AND {xen:time $serverTime, 'G'} < 20">
	MESSAGE
</xen:if>
Day of the week (0 for Sunday through 6 for Saturday):

Code:
<xen:if is="{xen:time $serverTime, 'w'} == 0">
	MESSAGE
</xen:if>
For reference, this uses PHP's date() parameters:

http://us2.php.net/manual/en/function.date.php
 

Edrondol

Well-known member
#5
Where would you put this code and would it have to be re-added each time an upgrade was done?

edit: I see what you mean. This has nothing to do with Notices. This is for normal text. Very odd.
 

DaveL

Well-known member
#6
Hi Jake,

Many thanks for that (y)

Ive just tried using the days of the week, but for some reason nothing seems to be showing up. This is the code im using

HTML:
<div class="section">
<div class="secondaryContent id="Html">
<h3>Playing Today on DCR</h3>

<div class="messageText ugc baseHtml">
 
<xen:if is="{xen:time $serverTime, 'w'} == 3">
    <strong>Wednesday</strong>
<p>6am to 7pm - DCR Non-Stop<br />
7pm to 8pm - Steve Banks<br />
8pm to 9pm - Albert Thorp's Meaningful Request Show<br />
9pm to 6am - DCR Non-Stop<br /></p>

</xen:if>
 
    </div>
    </div>
</div>
And this is what is displayed:
today.png

I dont suppose you can see from the code where abouts im going wrong can you?

Thanks again, Really appreciated

Dave
 

Jake Bunce

XenForo moderator
Staff member
#7
...

Day of the week (0 for Sunday through 6 for Saturday):

Code:
<xen:if is="{xen:time $serverTime, 'w'} == 0">
	MESSAGE
</xen:if>
...
Upon further testing this is not working for me. For some reason all numeric 'day of week' parameters aren't working. Maybe it's my server. Here is an alternative that works for me:

Code:
<xen:if is="{xen:time $serverTime, 'D'} == 'Wed'">
	MESSAGE
</xen:if>
 

DaveL

Well-known member
#8
Thanks Jake, Thats worked great, so is the time one :) Really appreciate that.

One last question, for the times, is it possible to use minutes as well as hours - Eg 19:30 - 20:15?

Thanks again
Dave
 

James

Well-known member
#9
If I'm following, you should be able to use:
Code:
{xen:time $serverTime, 'G:i:s'}
Which should return a time based on HH:MM:SS
 

DaveL

Well-known member
#10
<xen:if is="{xen:time $serverTime, 'G'} >= 19 AND {xen:time $serverTime, 'G'} < 20"> AND {xen:time $serverTime, 'D'} == 'Wed'">

Test
</xen:if>
Just having a little play and wanted to make sure im using the code the best way. The intention of the above is only display "Test" if it is Wednesday and its between 7pm and 8pm - Is this the best way to do it or should I use two IFs, one for date and one for time?

EDIT - Got it figured out!

<xen:if is="{xen:time $serverTime, 'D'} == 'Wed'">
<strong>Wednesday</strong><br />
<xen:if is="{xen:time $serverTime, 'G'} >= 6 AND {xen:time $serverTime, 'G'} < 19">
Test 1
</xen:if>
<xen:if is="{xen:time $serverTime, 'G'} >= 19 AND {xen:time $serverTime, 'G'} < 20">
Test 2
</xen:if>
<xen:if is="{xen:time $serverTime, 'G'} >= 20 AND {xen:time $serverTime, 'G'} < 21">
Test 3
</xen:if>
 

DaveL

Well-known member
#11
What should I use for midnight?

<xen:if is="{xen:time $serverTime, 'G'} >= 23 AND {xen:time $serverTime, 'G'} < 24">
Wednesday
</xen:if>

<xen:if is="{xen:time $serverTime, 'G'} >= 00 AND {xen:time $serverTime, 'G'} < 01">
Thursday
</xen:if>
Would the above work?
 

James

Well-known member
#12
Technically there is no "24" in a 24 hour clock. It's 00 - 23, so you'd probably use:
Code:
<xen:if is="{xen:time $serverTime, 'G'} = 00">
// code
</xen:if>
 

DaveL

Well-known member
#13
Ok, thanks James.

One final question, I think I may need to use the below piece of code

<xen:if is="{xen:time $serverTime, 'G'} >= 19 AND {xen:time $serverTime, 'G'} < 20"> AND {xen:time $serverTime, 'D'} == 'Wed'">

Test
</xen:if>
And it seems to work, however its also displaying some of the code in the output. Have I joined the time and day parts together correctly?
 

DaveL

Well-known member
#16
Thanks Brogan, that sorted it out :)

Will having these conditionals cause many problems, such as slow down etc?

I will to start with be having aprox 4 per day listed.
 

DaveL

Well-known member
#18
The answer I was really hoping for! Thanks Brogan :)

And thank you to everyone else who has helped out in this thread. Really appreciated and hopefully others will find it useful as well.
 

DaveL

Well-known member
#19
If I'm following, you should be able to use:
Code:
{xen:time $serverTime, 'G:i:s'}
Which should return a time based on HH:MM:SS
Hi James,

I had it working great using whole hours (19,20,21,22 etc) but today was the first time ive tried to add minutes.

When I added this:
<xen:if is="{xen:time $serverTime, 'G'} >= 00 AND {xen:time $serverTime, 'G:i'} < 19:30 AND {xen:time $serverTime, 'D'} == 'Mon'">
<img src="http://www.mydover.co.uk/dcrlogo.jpg" style="width: 140px; height:100px; margin-bottom: 5px;"></a>
<br><strong>DCR Non-Stop</strong>
</xen:if>
xenforo pops up the following error when I try to save:

The following templates contained errors and were not saved: EWRporta_Block_Timetable: 1) Line 7: Invalid condition expression
Line 7 relates to the first line in the top quote.

Any help really appreciated.