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.
Author |
Topic |
kka_anand
Starting Member
24 Posts |
Posted - 2010-10-24 : 10:28:57
|
Hi All,I have a requirement to find a last wednesday of a month.Example, For the current month October'2010 the last wednesday is 27-Oct-2010.For the next month November'2010 the last wednesday is 24-Nov-2010.Thanks in Advance...RegardsAnand |
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-24 : 12:18:14
|
[code]declare @dt datetime='12-may-2010'select case datename(dw,DATEADD(mm, DATEDIFF(mm,-1, @dt),-1))when 'sunday' then DATEADD(mm, DATEDIFF(mm,-1, @dt),-1)-4when 'monday' then DATEADD(mm, DATEDIFF(mm,-1, @dt),-1)-5when 'tuesday' then DATEADD(mm, DATEDIFF(mm,-1, @dt),-1)-6when 'wednesday' then DATEADD(mm, DATEDIFF(mm,-1, @dt),-1)when 'thursday' then DATEADD(mm, DATEDIFF(mm,-1, @dt),-1)-1when 'friday' then DATEADD(mm, DATEDIFF(mm,-1, @dt),-1)-2when 'saturday' then DATEADD(mm, DATEDIFF(mm,-1, @dt),-1)-3 end[/code]PBUH |
 |
|
|
|
|
|
|