Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
HiHow do i get the date for Last Thrusday of a particular monthi.e. for any month i should be able to find the date of last thursdayplease help...ThanksVidhya
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2008-01-30 : 06:03:33
[code]select MAX(date) AS LastThursdayfrom 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"
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 LastThursdayfrom ( select dateadd(day,number,cast(@month as datetime)) as date from master..spt_values where type='p' and number<32 ) twhere datename(weekday,date) = 'thursday'