Home › Forums › JavaScript › error Shop Open and Close Times script
- This topic is empty.
-
AuthorPosts
-
September 27, 2010 at 4:31 pm #30378
UFNITE
MemberI’m using javascript to display open/close times but my script is not working.
Dreamweaver says their is a syntax error on line 6
var d = new Date();
var t_hour = d.getUTCHours(); // getUTC for GMT0
var t_min = d.getUTCMinutes();
var t_day = d.getUTCDay();
if (t_hour == 8 && t_min >= 30 && t_day > 0 && t_day < = 5)
{
document.write('open.');
}
else if (t_hour > 8 && t_hour < 18 && t_day > 0 && t_day < = 5)
{
document.write('open.');
}
else
{
document.write('closed.');
}and in BODY
Our shop is.
September 28, 2010 at 3:22 am #78970Bob
MemberTry removing the space from line 6, almost all the way at the end of the line.
Line 6 is now:if (t_hour == 8 && t_min >= 30 && t_day > 0 && t_day < = 5)
whereas it should, I think, be:
if (t_hour == 8 && t_min >= 30 && t_day > 0 && t_day <= 5)
Edit: you have the same thing on line 10. Don't know for sure this causes the problem though.
I removed the space from between the < and the =
September 28, 2010 at 11:13 am #78978UFNITE
MemberThanks Bob, that worked.
Now to figure out how to sort the days and times
September 28, 2010 at 11:27 am #78981UFNITE
MemberMonday: CLOSED
Tuesday: 9AM – 5:30PM
Wednesday: 9AM – 5:30PM
Thursday: 9AM – 5:30PM
Friday: 12PM – 8PM
Saturday: 8AM – 2PM
Sunday: CLOSEDSay i tried to have
t_day 3 (tuesday) t_hour == 9 (is that pm or am?)
how would i specific a closing t_hour to be 5:30PM?
and if its any later than that how would it display the closed if statement… a greater than sign?
Thanks.
September 28, 2010 at 2:53 pm #78988Bob
Membert_hour == 9 is AM, since getUTCHours() returns the hour from 0-23. So 9 is still AM.
For 5:30PM, you could do the following:
var d = new Date();
var t_hour_minutes = d.getUTCHours() + ":" + d.getUTCMinutes();
if (t_hour_minutes > "17:30") {
document.write('closed');
}Edit: I’m not really good with timezones and all that stuff, 5:30PM would seem 17:30 to me, but it might be 18:30 or so because of daylights saving.. I don’t know, but this should get you started.
September 28, 2010 at 5:36 pm #78991UFNITE
MemberTuesday open 9:00am close 5:30pm – this doesn’t function properly any idea why?
if (t_hour == 9 && t_min >= 00 && t_day > 2 && t_day < = 2)
{
document.write('open');
}
else if (t_hour > 5 && t_hour < 17 && t_min >= 30 && t_day > 2 && t_day <=2)
{
document.write('open');
}September 28, 2010 at 5:39 pm #78992Bob
MemberThats because you made the same error again – you put a space between < and = on line 1. Remove that space.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.