Log in

View Full Version : Variable value based on time of day


pran
12-21-2005, 04:21 PM
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?

pran
12-22-2005, 12:11 PM
Can this go inside the template or the PHP files? How do I get the variable from the PHP to the template? Thanks!

merk
12-22-2005, 08:27 PM
You can put it in global_start and it will be available in almost all templates.

pran
12-22-2005, 09:22 PM
<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!

merk
12-22-2005, 09:36 PM
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.

pran
12-22-2005, 09:46 PM
I couldn't get to display it inside a script tag by using:

<?php print $coolvariable; ?>

merk
12-22-2005, 10:03 PM
nonono, just use $coolvariable inside templates. (by itself)