Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > ColdFusion

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-10-2011, 07:11 PM   PM User | #1
drumsinheaven
New Coder

 
Join Date: Sep 2009
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
drumsinheaven is an unknown quantity at this point
Create Multiple Date Values

Hello,

I'm trying to create a simple coldfusion script to display the correct operating hours of a building based on the date. I've got it working but I would like to add multiple dates to some of the rules. ie. If it is 5/3/11 or 5/4/11 or 5/5/11 display xyz hours. Here's what I've got thus far.

<cfoutput><h3>Today is #DateFormat(Now(),"dddd, mmmm d, yyyy")#</h3>
<cfset dow = dayofWeek(now())>
<cfset doy = dayofYear(now())>
<p>Building Hours: <cfif doy is #dayofYear(CreateDate(2011, 5, 9) or (2011, 5, 10)#>12:00pm - 8:00pm<cfelseif doy is #dayofYear(CreateDate(2011, 5, 11))#>8:00am - 6:00pm<cfelseif dow is 2 or 3 or 4 or 5>6:00am - 10:00pm<cfelseif dow is 6>6:00am - 8:00pm<cfelseif dow is 7>10:00am - 8:00pm<cfelseif dow is 1>10:00am - 10:00pm</p></cfif>

Thanks!
drumsinheaven is offline   Reply With Quote
Old 05-11-2011, 07:15 PM   PM User | #2
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
If statements must be "[comparison] OR [comparison]", not "if something is this OR that".

So your first cfif should look something like this:
Code:
<cfif doy is dayOfYear(createDate(2011, 5, 9)) OR doy is dayOfYear(createDate(2011, 5, 10))>
Your entire if statement block should probably look something along these lines:
Code:
<cfif doy is dayOfYear(createDate(2011, 5, 9)) OR doy is dayOfYear(createDate(2011, 5, 10))>
  12:00pm - 8:00pm
<cfelseif doy is dayofYear(createDate(2011, 5, 11))>
  8:00am - 6:00pm
<cfelseif dow is 2 OR dow is 3 OR dow is 4 OR dow is 5>
  6:00am - 10:00pm
<cfelseif dow is 6>
  6:00am - 8:00pm
<cfelseif dow is 7>
  10:00am - 8:00pm
<cfelseif dow is 1>
  10:00am - 10:00pm
</cfif>
Btw, you don't need to use the # signs inside the <cfif> tag. I removed them in the above code.

-Greg
Gjslick is offline   Reply With Quote
Users who have thanked Gjslick for this post:
drumsinheaven (05-12-2011)
Old 05-12-2011, 03:49 PM   PM User | #3
drumsinheaven
New Coder

 
Join Date: Sep 2009
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
drumsinheaven is an unknown quantity at this point
Works Great!

Thanks. It works. So cool!
drumsinheaven is offline   Reply With Quote
Reply

Bookmarks

Tags
cfelseif, cfif, coldfusion, createdate, dates

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:02 AM.


Advertisement
Log in to turn off these ads.