Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message based on day of week and time

Status
Not open for further replies.
May 12, 2002
51
US
Help, please! I'm not very good w/javascript.

Here's what I need to do: I need to display a different message for the following days & times:

FRI. 9PM-10PM
FRI. 10PM-11PM
FRI. 11PM-12AM
SAT. 12AM-1AM
SAT. 1AM-2AM
SAT. 2AM-3AM

SAT. 9PM-10PM
SAT. 10PM-11PM
SAT. 11PM-12AM
SUN. 12AM-1AM
SUN. 1AM-2AM
SUN. 2AM-3AM

How would I do this? I have found SEVERAL scripts that will display a message based on the current day of the week OR time. I cannot figure out how to make the two work together.

Pleeease, help! :eek:)

Thanks. Thanks!
-JusTin
 
Try this script, I have used a combination of switch (case) statements and if...else.

I wasn't sure if it was a message box you wanted to display or not, and what you wanted to display if it wasn't between these times.

You should be able to modify the code where the 'alert' statements are if you wanted it to do anything else instead.

Let me know if you have any trouble...

[tt]
function msg(){
//set up Time & Date variables for the current Day & Hour
var myDate = new Date() // returns full date
var today = myDate.getDay() //returns 1-7 (1 being monday)
var now = myDate.getHours() //returns 24 hour clock

switch(today)
{
case 5: //friday
if (21 < now < 22){ //compare current time
alert(&quot;friday 21pm-22pm&quot;);
}
else if (22 < now < 23){
alert(&quot;friday 22pm-23pm&quot;);
}
else if (23 < now < 00){
alert(&quot;friday 23pm-12am&quot;);
}
else {
alert(&quot;nothing&quot;);
}
break;
case 6: //saturday
if (12 < now < 1){ //compare current time
alert(&quot;saturday 12am - 1am&quot;);
}
else if (1 < now < 2){
alert(&quot;saturday 1am - 2am&quot;);
}
else if (2 < now < 3){
alert(&quot;saturday 2am - 3am&quot;);
}
else if (21 < now < 22){ //compare current time
alert(&quot;saturday 21pm-22pm&quot;);
}
else if (22 < now < 23){
alert(&quot;saturday 22pm-23pm&quot;);
}
else if (23 < now < 00){
alert(&quot;saturday 23pm-12am&quot;);
}
else {
alert(&quot;nothing&quot;);
}
break;
case 7: //sunday
if (00 < now < 1){ //compare current time
alert(&quot;sunday 12am - 1am&quot;);
}
else if (1 < now < 2){
alert(&quot;sunday 1am - 2am&quot;);
}
else if (2 < now < 3){
alert(&quot;sunday 2am - 3am&quot;);
}
else {
alert(&quot;nothing&quot;);
}
break;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top