?
Solved

Show message at a certain time of day with Coldfusion

Posted on 2008-06-11
5
Medium Priority
?
612 Views
Last Modified: 2013-12-20
Ok this has to be easy but I'm just not getting it. Any help would be awesome.

Say someone comes to a page on Monday after 5:30PM I want them to see one thing but if they came before 5:30PM they would see something else.

So say the time is 11:25 AM they would see a message saying Hi Good Morning
and if they went to the site at 5:30PM it would say Good Night
and on Saturday or Sunday it would say have a great weekend all day

How do I set something up like this?

thanks
0
Comment
Question by:gkeil
[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
  • 2
  • 2
5 Comments
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 800 total points
ID: 21766028

<cfset vTime=now()>


<cfif datepart("w",vTime) eq 1 or datepart("w",vTime) eq 7>
<cfset msg = "it's the weekend">
<cfelse>

<cfswitch expression="#datepart("h",vTime)#">
<cfcase value="6,7,8,9,10,11,12">
<cfset msg = "Good Morning">
</cfcase>
<cfcase value="13,14,15,16,17,18">
<cfset msg = "Good Afternoon">
</cfcase>
<cfcase value="19,20,21,22,23,24,1,2,3,4,5">
<cfset msg = "It's late. Don't you have a life?">
</cfcase>
</cfswitch>
</cfif>

<cfoutput>
#msg#</cfoutput>
0
 

Author Comment

by:gkeil
ID: 21766181
awesome but what if its 5:30PM and not just a solid time like 5:00PM?

thanks
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 1200 total points
ID: 21766829
How about this:
<cfset Now=now() >
<cfif ListFind("1,7",DayOfWeek(Now)) >
  <cfset greeting="Nice Weekend!" >
<cfelseif TimeFormat(Now, "hh.mm") LT "05.30" >
  <cfset greeting="something else" >
<cfelseif TimeFormat(Now, "hh.mm") LT "12.00" >
  <cfset greeting="Good Morning!" >
<cfelseif TimeFormat(Now, "hh.mm") LT "17.30" >
  <cfset greeting="Hello!" >
<cfelseif TimeFormat(Now, "hh.mm") GE "17.30" >
  <cfset greeting="Good Night!" >
</cfif>
 
<cfoutput> #greeting#</cfoutput>

Open in new window

0
 
LVL 36

Expert Comment

by:SidFishes
ID: 21768645
"what if its 5:30PM "

because we are only finding the h (hour) datepart my code will find any number within that hour 5:05, 5:30, 5:59 etc

if you need to set your changeover time to a half hour like before 5:30 it's afternoon and after 5:30 it's evening, then zvonkos code is how to do it...

both work, just different approaches

0
 

Author Comment

by:gkeil
ID: 21771260
Thanks for your help guys
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
What You Need to Know when Searching for a Webhost Provider
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

743 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