ColdFusion: Get variable string value from cfloop -


the code below outputs weekend dates in current month.

code:

<cfparam name="month" default="#datepart('m', now())#"> <cfparam name="year" default="#datepart('yyyy', now())#">  <cfset thismonthyear=createdate(year, month, '1')> <cfset days=daysinmonth(thismonthyear)>  <cfset thisday = 1> <cfloop condition="thisday lte days">     <cfset presentday = createdate(year, month, thisday)>     <cfif dayofweek(presentday) eq '7'>         <cfoutput>#thisday#</cfoutput>     <cfelseif dayofweek(presentday) eq '1'>         <cfoutput>#thisday#</cfoutput>     </cfif>     <cfset thisday = thisday + 1> </cfloop> 

output:
6 7 13 14 20 21 27 28

i'm trying pass value of cfloop in 1 variable. code below displays last weekend date value.

code:

<cfset thisday = 1> <cfset weekdayofmonth = ""> <cfloop condition="thisday lte days">     <cfset presentday = createdate(year, month, thisday)>     <cfif dayofweek(presentday) eq '7'>         <cfset weekdayofmonth = thisday>     <cfelseif dayofweek(presentday) eq '1'>         <cfset weekdayofmonth = thisday>     </cfif>     <cfset thisday = thisday + 1> </cfloop> <cfoutput>#weekdayofmonth#</cfoutput> 

output
28

question, need fix in last cfloop code can pass loop values jsweekenddates variable?

any appreciated.
thank you.

just figured on own. enjoy.

<cfset thisday = 1> <cfset weekday = ""> <cfloop condition='thisday lte days'>     <cfset presentday = createdate(year, month, thisday)>     <cfif dayofweek(presentday) eq '1' or dayofweek(presentday) eq '7'>         <cfset weekday = weekday & " " & thisday">     </cfif>     <cfset thisday = thisday + 1> </cfloop> <cfoutput>#weekday#</cfoutput> 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -