Solved

Show message at a certain time of day with Coldfusion

Posted on 2008-06-11
5
608 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 200 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 300 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
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…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

696 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