IE find the first monday of a month)" />
The primary distinguishing feature of ColdFusion is its associated scripting language, ColdFusion Markup Language (CFML), which compares to JSP, ASP.NET, or PHP and resembles HTML in syntax. "ColdFusion" is often used synonymously with "CFML", but it should be noted that there are additional CFML application servers besides ColdFusion, and that ColdFusion supports programming languages other than CFML, such as server-side Actionscript and embedded scripts that can be written in a JavaScript-like language, known as CFScript.
How to find particular day in a month.
Example shown: How to find the 2nd Wednesday of the month.
<cfset MonthArray[1][#loopCount#] = #DateFormat(this_month,'dddd')#>
<cfif MonthArray[1][#loopCount#] is 'Wednesday'>
<cfset maxwed = #loopCount#>
</cfif>
The result of the above query when run today would be that in #DateFormat(now(),'mmmm yyyy')# the 2nd Wednesday is on the #maxwed#th.
So here is how it works, I start by creating a variable that takes the current month and year in number format, and put it in a string that creates a mm/dd/yyyy value but forcing it be the first of the month.
Then we make a new array, in this case we are only going to need a 1 dimensional array.
Next is the loop, now for example, if you wanted to know what the first Monday of the month is you would set the loop to be from 1 to 7. Logic being that there are only seven days in a week and if you want the first instance of the value "Monday" you only need to loop for 1 week. The loop creates a value that is the text version of day of the week, then an IF statement stores the numerical value if the value is in this example, 'Wednesday'. Now since I want the LAST Wednesday, I will let the value get over written, this way when I call the variable, its the last successful iteration of the if statement being true.
The last obvious question is, why create the array? Yes, you could do this without the array, however I like to build so that I can make additions quickly.
One of the sites that I worked with was an Aero Club and we used a slightly different version of the script above. In this case on the meeting announcement page we need to let the membership know when the next board meetings will be. However if the meeting for this month has already passed, then we need the dates to adjust. Also we need to not only show what this months meeting date is, but next months. Here is how this is done.
<cfset MonthArray[1][loopCount] = DateFormat(this_month,'dddd')>
<cfset MonthArray[2][loopCount] = DateFormat(next_month,'dddd')>
<cfset MonthArray[3][loopCount] = DateFormat(third_month,'dddd')>
<cfif MonthArray[1][loopCount] is 'Wednesday'>
<cfset max_this_wed = DateFormat(now(),'mm')&"/"&LoopCount&"/"&dateFormat(now(),'yyyy')>
</cfif>
<cfif MonthArray[2][loopCount] is 'Wednesday'>
<cfset max_next_wed = DateFormat(now(),'mm')+1&"/"&LoopCount&"/"&dateFormat(now(),'yyyy')>
</cfif>
<cfif MonthArray[3][loopCount] is 'Wednesday'>
<cfset max_third_wed = DateFormat(now(),'mm')+2&"/"&LoopCount&"/"&dateFormat(now(),'yyyy')>
</cfif>
<Cfset this_month = dateAdd('d',1,this_month)>
<Cfset next_month = dateAdd('d',1,next_month)>
<Cfset third_month = dateAdd('d',1,third_month)>
<cfif this_month lt Now()>
<Cfset even = max_third_wed>
<cfelse>
<Cfset even = max_this_wed>
</cfif>
<cfset odd = max_next_wed>
<cfelse>
<Cfset even = max_next_wed>
<cfif this_month lt Now()>
<Cfset ODD = max_third_wed>
<cfelse>
<Cfset ODD = max_this_wed>
</cfif>
You can see that basically we are doing the same function as in the original example, but this time we are adding two more months to the mix. The last IF statement is what is used to tell if today is greater than the meeting date for this month, and if it is, then jump the next month for that particular meeting type.
Feel free to leave a comment or question
Code block comments
2010-03-19
Added a code block for comments
Windows 7 Items
2009-09-24
new info on windows 7
Snort on Debain Lenny
2009-08-19
Installing snort+PGSQL on Debian