Solved

Show message at a certain time of day with Coldfusion

Posted on 2008-06-11
5
607 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
  • 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

How our DevOps Team Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web Site Hosting 10 89
.dwt files not viewable in browser - why? 2 93
DNS, website, godaddy 6 86
Summernote required 3 144
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

825 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