House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Next "X" days - but SKIP the weekend

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Les Mizzell
05/12/2004 03:54 PM

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? ---------------------------------------

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
05/12/2004 04:10 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jeff Garza
05/12/2004 04:13 PM

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?   ---------------------------------------

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
05/12/2004 04:02 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
05/12/2004 04:10 PM

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. >

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
05/12/2004 04:20 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Les Mizzell
05/12/2004 06:13 PM

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? ---------------------------------------


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

February 08, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29