Hi
I want query which returns the last month from the current date.
for ex: if i enter today date then it should return the 12.
if i enter the date '2010-02-31' then it should return 1
thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Gaurish KumarPosted Jan 31, 2010, 11:41 PM
try this
SELECT DATEPART(MONTH,CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(GETDATE())),GETDATE()),101))
this query returns what you want.
ImranPosted Jan 31, 2010, 11:47 PM
it's solve my problem.