PDA

View Full Version : Diff Image @ time of day


Zardoz
08-09-2002, 04:08 PM
I know I've seen this script somewhere before but I couldn't find it, so I apologize for taking up anyone's time who'se seen this already.

Anyway - I'm looking for a simple script that will change the SRC for an image depending on the time of day. It's for a restaurant, and I'd like to show their lights either off, dim, and on depending on the time someone access the site. Thanks in advance for any help!

requestcode
08-09-2002, 04:15 PM
Here is a link to a script from JavaScriptKits Free Scripts Section that displays an image based on whether it is night or day. You should be able to modify it for your needs.
http://www.wsabstract.com/script/cut6.shtml

Zardoz
08-09-2002, 04:24 PM
Thanks!

sd12013
05-26-2008, 10:22 AM
First, I'm a code noob. That being said...

Can this script be modded to show a different image based on fractions of hours like 8:15, 8:30, 8:45 etc? Maybe my syntax is incorrect but when I edit it to something like this and set my system clock to 8:20pm:

if (x>=20 && x<20.25) {
document.write("<img src='image1.jpg'>")
} else
if (x>=20.25 && x<20.5) {
document.write("<img src='image2.jpg'>")

It still shows image1.jpg where I thought it would show image 2. Does it not accept fractions of hours or am I just coding it wrong? Also, is there a way to make it so the script only runs on a particular day such as March 17 and all other days show a different image?

Thanks for you help.
-Rob

Philip M
05-26-2008, 04:26 PM
Here is the general syntax of what you require:-

<script type = "text/javascript">

var now = new Date();
var hh = now.getHours();
var mn = now.getMinutes();

if (hh>=20 && mn>25) { // time after 2025
document.write("<img src='image1.jpg'>")
}
if (hh>=20 && mn<=25) { // time from 2000 to 2025
document.write("<img src='image2.jpg'>")
}
else { // at all other times 0000 - 2000
document.write("<img src='image3.jpg'>")
}

</script>

<script type = "text/javascript">
var now = new Date();
var mnth = now.getMonth();
var dd = now.getDate();
if (mnth == 2 && dd == 17) { // March 17th - note months are 0-11
document.write("<img src='image1.jpg'>");
}
else {
document.write("<img src='image2.jpg'>"); // all other dates
}

</script>


Caller: "I deleted a file from my PC last week and I have just realised that I need it. If I turn my system clock back two weeks will I have my file back again?".

binaryWeapon
05-27-2008, 03:55 AM
Caller: "I deleted a file from my PC last week and I have just realised that I need it. If I turn my system clock back two weeks will I have my file back again?". LMAO, I actually tried that when I was young! XD

barkermn01
05-27-2008, 04:44 PM
it is easy php or javascript


$time = date(H);
if($time < 12){
$location = '[pick location]';
}
Javascript almost identical
just setup a class to date for the time and remove the $