And here's some SQL on 2000...

This first bit gives you the days in a month:


SET DATEFORMAT dmy, DATEFIRST 7

DECLARE @now DATETIME, @firstOfNextMonth DATETIME, @lastOfCurrentMonth
DATETIME, @daysInMonth INT

SELECT @now = '20/01/2005'

SELECT @firstOfNextMonth = '01/' + CAST(MONTH(@now) + 1 AS VARCHAR(2)) + '/'
+ CAST(YEAR(@now) AS VARCHAR(4))

SELECT @lastOfCurrentMonth = DATEADD(d, -1, '01/' +
CAST(MONTH(@firstOfNextMonth) AS VARCHAR(2)) + '/' +
CAST(YEAR(@firstOfNextMonth) AS VARCHAR(4)))

SELECT @daysInMonth = DAY(@lastOfCurrentMonth)



This part gives you the date of the last of a given day, in this case,
Thursday(5):



DECLARE @endOfTheMonth DATETIME, @days INT, @dayToFind INT

SELECT @dayToFind = 5 -- A Thursday

SELECT @endOfTheMonth = CAST(@daysInMonth AS VARCHAR(2)) + '/' +
CAST(MONTH(@now) AS VARCHAR(2)) + '/' + CAST(YEAR(@now) AS VARCHAR(4))

IF DATEPART(weekday, @endOfTheMonth) >= @dayToFind BEGIN
        SELECT @days = DATEPART(weekday, @endOfTheMonth) - @dayToFind;
END ELSE BEGIN
        SELECT @days = 7 - @dayToFind + DATEPART(weekday, @endOfTheMonth);
END

SELECT DATEADD(d, [EMAIL PROTECTED], @endOfTheMonth) 'The Last Thursday'


How does that work for you?

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


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware: a new and convenient web-based time tracking application. Start 
tracking and documenting hours spent on a project or with a client with Logware 
today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:191429
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

Reply via email to