• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 611
  • Last Modified:

Conditionally display content based on time of day

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  %>
<% else if ctime => "11:01" and ctime <= "14:00" then  %>
<% else %>
<% end if %>
<% end if %>

Open in new window

  • 4
  • 3
1 Solution
Paul MacDonaldDirector, Information SystemsCommented:
That looks okay to me.
freezillaAuthor Commented:
And basically just build up from there?
Paul MacDonaldDirector, Information SystemsCommented:

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.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

freezillaAuthor Commented:
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.
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Is there a problem with your code?

Another good option is to create a procedure.

response.write "We are now server "& getdaypart

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

End Function
Paul MacDonaldDirector, Information SystemsCommented:
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!
freezillaAuthor Commented:
Paul MacDonaldDirector, Information SystemsCommented:
Ah, well.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now