View Full Version : Variable value based on time of day
I have a variable that I want to change based on the time of day. For example, it would have a specific value from 12:00mn to 7:00am and another value from 7:00am to 12:00mn, and so on and so forth. How do I do this?
noppid
12-21-2005, 05:07 PM
$my_date = intval(date("H"));
if( $my_date >= 0 && $my_date <= 6)
{
// do stuff for midnight to 7am
}
if( $my_date >= 7 && $my_date <= 23)
{
// do stuff for 7am to midnight
}
something like that maybe?
Can this go inside the template or the PHP files? How do I get the variable from the PHP to the template? Thanks!
You can put it in global_start and it will be available in almost all templates.
<span style="text-decoration: line-through">Thanks! How do you now display this variable in the template?</span>Never mind, I used template conditionals instead. Thanks!
Well, if for example the code you put into global_start looked like
$my_date = intval(date("H"));
if( $my_date >= 0 && $my_date <= 6)
{
$coolvariable = "Its between midnight and 7am";
}
if( $my_date >= 7 && $my_date <= 23)
{
$coolvariable = "Its between 7 am and midnight";
}
You would just simply put $coolvariable in a template, for example, navbar.
I couldn't get to display it inside a script tag by using:
<?php print $coolvariable; ?>
nonono, just use $coolvariable inside templates. (by itself)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.