Solved

Show message at a certain time of day with Coldfusion

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intranet and Kerberos Authentication (not sharepoint!) 8 118
spamming  on Hosted svrs? 6 74
System Analysis 5 52
site launch date and last modified date 3 83
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…
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 manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

896 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

14 Experts available now in Live!

Get 1:1 Help Now