How do I assign a value to a variable depending on the time of the day?
For example: If time is between 2am to 4pm, variable = 50.
How can I accomplish this?
Thanks for any help. :)
As long as you remember that you are dealing with a 24 hour clock, and have a firm grasp of greater/lesser than and greater/lesser or equal to, it's no problem.
<?
$switchvar = 0;
$hour = date('H');
if ($hour <= 16 and $hour >= 2) $switchvar = 50;
echo $switchvar;
?>
Thanks Feyd. That would get me started. :)
What if I want to breakdown the variable assignment in 30-minute intervals for example? :confused:
How do I use the date function to return the value in minutes or seconds?
Phantom
02-12-2003, 09:04 PM
Minutes is i (00 - 59), seconds is s (00-59)
IE:
$minute = date('i');
Or
$second = date('s');
:)
But that would only give me values from 0 to 60 for a given hour or for a given minute.
I want the date function to return values in seconds or minutes for a day instead of just 0 to 23 (using the "G" format).
Like so:
0 to 1440 (one whole day by the minutes)
0 to 86400 (one whole day by the seconds)
For example between 7:16 am to 7:46 am, variable = 12. The "G" format is inadequate for this.
Any ideas? :)
djbruno
02-14-2003, 12:38 AM
maybe u should try to do like this
$hour = date('H);
$minute = date('i');
$second = date('s');'
# now u can calculate how many seconds elapsed so far today!
$number = ($hour*60*60)+($minute*60)+$second;
# then u do assign any value to your variable acording to $number.
hope it helped.
:thumbsup:
Thanks djbruno it helped. :)
Or I can also try something like this:
if (strftime("%H:%M",time())>"14:00" && strftime("%H:%M",time())<"16:00")
$variable=50;
elseif ......