2
Answers

want query in sql server

Imran

Imran

15y
2.4k
1
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
Answers (2)
0
Gaurish Kumar
NA 912 0 15y
Hi Imran

try this

SELECT DATEPART(MONTH,CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(GETDATE())),GETDATE()),101))

this query returns  what you want.
Accepted
0
Imran
NA 3 0 15y
Thanks Gaurish for quick reply.
it's solve my problem.