Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / July 2006



Tip: Looking for answers? Try searching our database.

Extract WeekEnds

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DJ5MD - 28 Jul 2006 16:18 GMT
:frown;
How can I use the ( #DayofWeek(datefield)#  NEQ 1 or 7 ) on the following loop
code to remove (not display) weekends dates?

<cfloop from="#GetStartDate.StartDate#" to="#GetEndDate.EndDate#" index="i">
        <cfset variables.keyvalue = DateFormat(i, "YYYY/MM/DD")>
        <cfset structDaysTemplate["#variables.keyvalue#"] = "">
        <cfset structRooms.Days["#variables.keyvalue#"] = "#DateFormat(i, "MM/DD")#">
        <cfset structRooms.Totals["#variables.keyvalue#"] = 0>
</cfloop>
Dan Bracuk - 28 Jul 2006 16:29 GMT
The general idea is
<cfif DayofWeek(datefield) is not 1
or DayofWeek(datefield) is not 7>

Or you could be positive about the whole thing and do this
<cfif ListFind("2,3,4,5,6", DayofWeek(datefield)) is true>
DJ5MD - 28 Jul 2006 16:30 GMT
Correct Dan, but where would I but this code within my loop.  I kept trying and it wasn't working correctly.
paross1 - 28 Jul 2006 16:43 GMT
[Q]The general idea is
<cfif DayofWeek(datefield) is not 1
or DayofWeek(datefield) is not 7>[/Q]

Dan, wouldnt' that be AND?

<cfif DayofWeek(datefield) is not 1 [b]AND[/b] DayofWeek(datefield) is not
7>[/Q]

Phil
DJ5MD - 28 Jul 2006 16:54 GMT
Phil,

It would be 1 OR 7, because were filtering for 2 values.  If you said 1 AND 7,
it won't filter because the value (DayofWeek) for a specific Date will never be
1 AND 7.  Meaning the date 10/15/2006 can never have a DayofWeek value of 1
(Sunday) and 7 (Saturday).  It will be one or the other.

Hope that helps.
paross1 - 28 Jul 2006 17:06 GMT
I was thinking in terms of NOT displaying weekend dates, rather than filtering FOR them. Notice that I didn't say 1 AND 7, the statement says NOT 1 [i]AND[/i] NOT 7, which is quite different.

Phil
Dan Bracuk - 28 Jul 2006 17:31 GMT
[q][i]Originally posted by: [b][b]paross1[/b][/b][/i]
[Q]The general idea is
<cfif DayofWeek(datefield) is not 1
or DayofWeek(datefield) is not 7>[/Q]
Dan, wouldnt' that be AND?
<cfif DayofWeek(datefield) is not 1 [B]AND[/B] DayofWeek(datefield) is not
7>[/Q]
[/q]
Of course it would.
paross1 - 28 Jul 2006 18:16 GMT
OK, think about it. When using OR, if DayofWeek(datefield) is actually 7, and
it hits the first test of DayofWeek(datefield) is not 1, then the CFIF would be
TRUE and it would never perform the second test to see if DayofWeek(datefield)
is not 7. Using the NOT [i]requires[/i] that you use AND.Phil
DJ5MD - 28 Jul 2006 18:21 GMT
:grin;

Gotcha Phil, I misunderstood.

Anyway, here is the code that worked for my loop:

<!--- Looping queries to get range of dates and filtering out Weekend dates
--->
<cfloop from="#GetStartDate.StartDate#" to="#GetEndDate.EndDate#" index="i">
     [b][i]<cfif (dayOfWeek(i) gt 1) AND (dayOfWeek(i) lt 7)>[/i][/b]
         <cfset variables.keyvalue = DateFormat(i, "YYYY/MM/DD")>
        <cfset structDaysTemplate["#variables.keyvalue#"] = "">
        <cfset structRooms.Days["#variables.keyvalue#"] = "#DateFormat(i, "MM/DD")#">
        <cfset structRooms.Totals["#variables.keyvalue#"] = 0>
    </cfif>
</cfloop>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.