Solved

Conditionally display content based on time of day

Posted on 2012-03-22
8
601 Views
Last Modified: 2012-06-21
Ok, I've looked around but as per usual can't find exactly what I'm looking for.  So here goes...
 
 Ultimately I'm going to build a digital cafeteria menu for my employer, but as of right now I'm just laying the groundwork.
 
 I'm trying to create a page that conditionally displays content based on the time of day.  Obviously this will be "Breakfast", "Lunch" and "Dinner."
 
 I'm going to use an Access DB and Classic ASP (that's the way my company is structured), so anything in ASP/VB script is what I'm looking for.
 
 Here's what code I have so far, would this be the right approach or if someone has something better/more efficient - I'm all ears.

<% 
ctime = FormatDateTime(Time,vbShortTime)
if ctime => "08:00" and ctime <= "11:00" then  %>
       
Breakfast
<% else if ctime => "11:01" and ctime <= "14:00" then  %>
       
Lunch
	  
<% else %>
Dinner
	  
<% end if %>
<% end if %>

Open in new window

0
Comment
Question by:freezilla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 37753163
That looks okay to me.
0
 

Author Comment

by:freezilla
ID: 37753177
And basically just build up from there?
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 37753202
Yep!

I think the hard part here will be coming up with an easy way to keep your database up-to-date.  Either you'll need to make a front end for that (so someone else can easily do it) or they'll just keep coming to you to do it.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:freezilla
ID: 37753215
No way.  I'm making a back end admin so that they can enter the items themselves.  I think the only thing that might throw me a bit is that the schedule differs on weekends as opposed to week days.
0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 37753239
Is there a problem with your code?

Another good option is to create a procedure.

<%
response.write "We are now server "& getdaypart


Function getdaypart()
      theHour=hour(now())
      if theHour > 8 AND theHour <=11 then
           theDayPart= "Breakfast"
       elseif theHour >11 and theHour <= 14 then
            theDayPart = "Lunch"
       else
            theDayPart = "dinner"
       end if
     
       getdaypart=theDayPart

End Function
%>
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 37753262
You can do some more conditional code using something like
     numDay = DatePart("w", Now())
to find the day of the week.

If you want to be really slick (and if the menu isn't longer than a typical page) you could put
<meta http-equiv="refresh" content="60">
in the header and have the page refresh itself every minute.  Then, when the time rolls from one meal to the next, the page will automatically show what's currently being served.

Good luck!
0
 

Author Closing Comment

by:freezilla
ID: 37753288
Nice!
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 37753337
Ah, well.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question