|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Next "X" days - but SKIP the weekend
Afternoon,Les Mizzell 05/12/04 03:54 P Check out the dayOfWeek() function. That'll help you decide if a day is aBarney Boisvert 05/12/04 04:10 P Use the Dayofweek() function to figure out what day today is (1-7) and then SWITCH/CASE through any days that might be affected.Jeff Garza 05/12/04 04:13 P You might try <cfset enddate = #DateAdd("w", 5, now)#>. The documentation says that 'w' equals weekday.Ian Skinner 05/12/04 04:02 P Well shoot. Please ignore my previous email where I implemented thisBarney Boisvert 05/12/04 04:10 P BarneyIan Skinner 05/12/04 04:20 P What I got to work was to do a query returning the next 7 days, and thenLes Mizzell 05/12/04 06:13 P Afternoon, Can't quite seem to get my head around this. I need to show an event list on a site that always list today and the next 4 days. But....if any of those days = weekend - it has to SKIP those and move on.. So Thursday Listing Friday Listing Monday Listing Tuesday Listing Wednesday Listing No problem doing this and *including* the weekend dates. Something like: <cfset now = Now()> <cfset enddate = #DateAdd("d", 5, now)#> Then: show everything equal or less than #enddate# and equal or greater than today.... ....but I'm not sure how to go about skipping dates that fall on Saturday or Sunday. Ideas? -- Les Mizzell --------------------------------------- Do geeks die when exposed to sunlight? --------------------------------------- Check out the dayOfWeek() function. That'll help you decide if a day is a weekend, and consequently you need to increment your numDays. An easy (though not necessarily the best) way to approach the problem is to make a loop from 1 to the number of days you need. Set a variable to the start date, and each iteration of the loop add one day. After adding the day, check the day of the week it's on. If it's a weekend, decrement your counter variable because even though you added a day, it doesn't count: <cfscript> // required variables startDate = now(); numDays = 5; // calulate end endDate = startDate; for (i = 1; i LTE numDays; i = i + 1) { endDate = dateAdd("d", 1, endDate); if (listFind("1,7", dayOfWeek(endDate)) GT 0) { numDays = numDays + 1; } } </cfscript> Cheers, barneyb ----- Excess quoted text cut - see Original Post for more ----- Use the Dayofweek() function to figure out what day today is (1-7) and then SWITCH/CASE through any days that might be affected. <CFSET Now = Now()> <CFSET dowToday = DayOfWeek(Now)> <CFSWITCH expression="#dowToday#"> <!--- Sunday ---> <CFCASE value="1"><cfset enddate = #DateAdd("d", 5, now)#></CFCASE> <!--- Monday---> <CFCASE value="2"><cfset enddate = #DateAdd("d", 5, now)#></CFCASE> <!--- Tuesday---> <CFCASE value="3"><cfset enddate = #DateAdd("d", 6, now)#></CFCASE> <!--- Wednesday---> <CFCASE value="4"><cfset enddate = #DateAdd("d", 6, now)#></CFCASE> <!--- Thursday---> <CFCASE value="5"><cfset enddate = #DateAdd("d", 6, now)#></CFCASE> <!--- Friday---> <CFCASE value="6"><cfset enddate = #DateAdd("d", 6, now)#></CFCASE> <!--- Saturday---> <CFCASE value="7"><cfset enddate = #DateAdd("d", 6, now)#></CFCASE> </CFSWITCH> Kinda ugly but it should work. This is untested code so you might have to tweak the number of days to add to get it working right. Cheers, Jeff Garza Afternoon, Can't quite seem to get my head around this. I need to show an event list on a site that always list today and the next 4 days. But....if any of those days = weekend - it has to SKIP those and move on.. So Thursday Listing Friday Listing Monday Listing Tuesday Listing Wednesday Listing No problem doing this and *including* the weekend dates. Something like: <cfset now = Now()> <cfset enddate = #DateAdd("d", 5, now)#> Then: show everything equal or less than #enddate# and equal or greater than today.... ....but I'm not sure how to go about skipping dates that fall on Saturday or Sunday. Ideas? -- Les Mizzell --------------------------------------- Do geeks die when exposed to sunlight? --------------------------------------- You might try <cfset enddate = #DateAdd("w", 5, now)#>. The documentation says that 'w' equals weekday. Confidentiality Notice: This message including any attachments is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender and delete any copies of this message. Well shoot. Please ignore my previous email where I implemented this long-hand. ;) Cheers, barneyb > You might try <cfset enddate = #DateAdd("w", 5, now)#>. The > documentation says that 'w' equals weekday. > Barney Maybe not completely ignore. If Les does not desire to display the days Saturday or Sunday, then a quick check of the dayofweek of each day as it's displayed will skip over them. Something basically like this loop from now() to dateAdd("w",5,now()) as indexDay if dayOfWeek(indexDay) NEQ 1 and dayOfWeek(indexDay) NEQ 7 display events else skip day end loop Confidentiality Notice: This message including any attachments is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender and delete any copies of this message. What I got to work was to do a query returning the next 7 days, and then filter the results with the "dayOfWeek" function. <cfoutput query="myquery"> <cfif dayOfWeek(myquery.Event_Date) NEQ 1 and dayOfWeek(myquery.Event_Date) NEQ 7> #MY OUTPUT STUFF# </cfif> </cfoutput> Thanks to all that replied - great help! -- Les Mizzell --------------------------------------- Do geeks die when exposed to sunlight? ---------------------------------------
|
February 08, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||