473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

changing a variable based on time of day

I want to set a value of a variabel $var based on the time of day
eg
if time is between 10:00pm and 9:00 am
set $var = "foo"

if time is between 9:00 am and 7.00pm
set $var = "bar"

if time is between 7.00pm and 10.00pm
set $var to "foobar"
how do i do this with the timestamp function?
many thanks

craig
Jul 17 '05 #1
2 2056

Craig Keightley wrote:
I want to set a value of a variabel $var based on the time of day
eg
if time is between 10:00pm and 9:00 am
set $var = "foo"

if time is between 9:00 am and 7.00pm
set $var = "bar"

if time is between 7.00pm and 10.00pm
set $var to "foobar"


Here's one way of doing it:
<?
$now_time = date('G',strtotime('now'));
echo $now_time."<br>\n";
$var = 'foo';
switch (TRUE) {
case ($now_time >= 9 && $now_time <= 19):
$var = 'bar';
break;
case ($now_time > 7 && $now_time <= 22):
$var = 'foobar';
break;
}
echo '$var:' . $var . "<br>\n";
?>

Ken

Jul 17 '05 #2
NC
Craig Keightley wrote:

I want to set a value of a variabel $var based
on the time of day
eg
if time is between 10:00pm and 9:00 am
set $var = "foo"

if time is between 9:00 am and 7.00pm
set $var = "bar"

if time is between 7.00pm and 10.00pm
set $var to "foobar"

how do i do this with the timestamp function?


First of all, there is no timestamp() function in PHP.
You need to use date() function:

$hour = date('G');
$var = "foo";
if (($hour >= 9) and ($hour < 19)) {
$var = "bar";
}
if (($hour >= 19) and ($hour < 22)) {
$var = "foobar";
}

Cheers,
NC

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ken Fine | last post by:
I have a menu system that has nodes that can be opened or closed. In an effort to make my code more manageable, I programmed a little widget tonight that keeps track of the open/active item and...
55
by: Ton den Hartog | last post by:
Stupid basic question but I find it horribly imposible to find the answer elsewhere... :-( I want to have a piece of text in my HTML page and want to be able to change it in a Javascript...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
10
by: Altman | last post by:
I have only done a little programming in C++ so I am still learning but I am having a problem with a variable that is changing on me. I have tried this 2 ways with the same result. I have a...
2
by: Chris Stankevitz | last post by:
Hi, I have some weird behavior in a very large (500,000 line) program that I boiled down to a few lines: TCSensorMode::ProcessMeasurement() { InternalComplicatedFunction(1.0, 2.0); int a =...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment (to learn enough ASP/VB.net to port a series of ...
3
by: Tim_Mac | last post by:
hi, i'm using a web application project in VS2005. i have a User Control Template.ascx in the '~/UserControls' folder with the following signature: public partial class GpTemplate :...
4
by: Mikael Olofsson | last post by:
Hi! This is in Python 2.3.4 under WinXP. I have a situation where I think changing the behaviour of a namespace would be very nice. The goal is to be able to run a python file from another in...
9
by: David | last post by:
With a non-server app there is one instance of the program running and one user 'using' it at a time. With this scenario I'm pretty comfortable with variable scope and lifetime. With a server app...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.