Or another way...
<cfscript>
function LastOfADay(theDayOfWeek) {
var days = 0;
var endOfTheMonth = CreateDate(Year(today), Month(today),
DaysInMonth(today));
if ( DayOfWeek(endOfTheMonth) GTE theDayOfWeek ) {
days = DayOfWeek(endOfTheMonth) - theDayOfWeek;
} else {
days = 7 - theDayOfWeek + DayOfWeek(endOfTheMonth);
}
return DateAdd("d", -days, endOfTheMonth);
}
</cfscript>
<cfoutput>
<cfloop from="1" to="7" index="i">
What's the last #DayOfWeekAsString(i)# of the month:
#DateFormat(LastOfADay(i), "dd/mm/yy")#<br />
</cfloop>
</cfoutput>
Ade
-----Original Message-----
From: Adrian Lynch [mailto:[EMAIL PROTECTED]
Sent: 22 January 2005 08:34
To: CF-Talk
Subject: RE: OT-SQL DATE QUESTION
To make M!ke's words come alive...
<cfset counter = 1>
<cfset today = Now()>
<cfset endOfTheMonth = CreateDate(Year(today), Month(today),
DaysInMonth(today))>
<cfoutput>
<cfloop from="#DaysInMonth(today)#" to="1" index="i" step="-1">
<cfif DayOfWeek(DateAdd("d", -counter, endOfTheMonth)) EQ 5>
The last Thursday is: #DateFormat(DateAdd("d", -counter,
endOfTheMonth),
"dd/mm/yyyy")#
<cfbreak>
</cfif>
<cfset counter = counter + 1>
</cfloop>
</cfoutput>
... I know you asked for a SQL answer, but ColdFusion is so much more fun
:OD
I only checked this on a few months and I reckon there might be a simpler
answer.
Ade
-----Original Message-----
From: Dawson, Michael [mailto:[EMAIL PROTECTED]
Sent: 20 January 2005 19:04
To: CF-Talk
Subject: RE: OT-SQL DATE QUESTION
I think you will need to loop backwards from the last day of the month
until you find the first (last) Thursday. You will probably need to put
this in a stored procedure.
You will also need to use a date function that returns "Monday",
"Tuesday", etc so you can look for "Thursday". Then, you can make note
of that particular date and compare it to the passed-in date.
M!ke
-----Original Message-----
From: Adkins, Randy [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 20, 2005 10:25 AM
To: CF-Talk
Subject: RE: OT-SQL DATE QUESTION
Are you trying to determine what day of the month, the last Thursday
falls on Or just if the 31st in this case is a Thursday?
-----Original Message-----
From: Eric Creese [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 20, 2005 11:19 AM
To: CF-Talk
Subject: OT-SQL DATE QUESTION
Okay I have a function that retrieves the last day of the month based on
feeding it todays date which would return 1/31/2005. I am trying to
modify this function to determin if today is the last Thursday of the
month. Does anyone have any ideas for this? I have tried a few things
like using the day of the week number but I am getting nothing and
looked out on the web and have not found much. This is for SQL2K
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.2 - Release Date: 21/01/2005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:191428
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54