Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Getting Last Thursday of Month

Author  Topic 

vidhya03
Starting Member

1 Post

Posted - 2008-01-30 : 05:54:33
Hi

How do i get the date for Last Thrusday of a particular month
i.e. for any month i should be able to find the date of last thursday

please help...

Thanks
Vidhya

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-30 : 06:03:33
[code]select MAX(date) AS LastThursday
from f_table_date('20080101', '20081231')
where weekday_name = 'thu'
group by year_month[/code]

Function f_table_date can be found here on SQLTeam.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-30 : 07:14:53
or


declare @month varchar(10)
set @month='Mar2008'

select MAX(date) AS LastThursday
from (
select dateadd(day,number,cast(@month as datetime)) as date from master..spt_values
where type='p' and number<32
) t
where datename(weekday,date) = 'thursday'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -