Hi,
Some time we need to find different dates of the months. Here are some examples..
Date on last Tuesday
Everyday of the week can be identified as a number i.e. Sunday is 1, Monday is 2 and so on
declare @date datetime
set @date = getdate() -- You can set any date here
select @date - (DatePart(dw, @date)-3)
----Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
----Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
----Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))
Thx,
RS