Solved

Show message at a certain time of day with Coldfusion

Posted on 2008-06-11
5
603 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
Comment Utility

<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
Comment Utility
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
Comment Utility
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
Comment Utility
"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
Comment Utility
Thanks for your help guys
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
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…

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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now