On Thu, Oct 8, 2009 at 4:01 PM, Matthew Smith <[email protected]> wrote:
>
> Users can vote in a contest each week from 5 pm Thursday until 5 pm next 
> Thursday, when the next week begins.  How do I find 5 pm Thursday just past?

These are fun challenges.

I'd wager money there's a better way to do this.  They key to my
solution is the iif() statement.  Most of the rest is just code to
show it works.

Paste binned:  http://cfm.pastebin.com/m175b5a7d

<pre>
Stuff I wrote down to figure out some math...

6 friday -1
7 saturday -2
 1 sunday -3
2 monday -4
3 tuesday -5
4 wednesday -6
5 thursday -7
</pre>

<cfloop from="0" to="7" step="1" index="i">
<!--- use this to test the time before or after 5pm --->
<cfset hourOffset = 1>
<!--- date to test --->
<cfset testDate = DateAdd('h',hourOffset, Now()+i)>
<cfoutput>
testDate = #DateFormat(testDate,"dddd, mmmm d, yyyy")#  @
#timeFormat(testDate, 'h:mm tt')#<br/>
<cfset theDiff = iif(DayOfWeek(testDate) gt 5 or (DayOfWeek(testDate)
eq 5 and hour(testDate) gte
17),"0-(DayOfWeek(testDate)-5)","0-DayOfWeek(testDate)-2")>
<cfset newDate = dateAdd('d',theDiff, testDate)>
<cfset lastThursday = createDateTime(Year(newDate), month(newDate),
day(NewDate), 17, 0, 0)>
Last Thursday at 5pm = #dateFormat(lastThursday,'dddd, mmmm d, yyyy')#
@ #timeFormat(lastThursday, 'h:mm tt')#
<Br/><br/>
</cfoutput>
</cfloop

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:327049
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to