August 22, 2014 at 2:28 pm
Hello All,
How do I get first day of last month of previous quarter from today's date? I know my question is little confusing. I need to get 06/01/2014 using t-sql. Can somebody give me a hand on this?
Thanks,
August 22, 2014 at 2:35 pm
It's easy with some date math.
You can find common date routines in here to try to understand them:
http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/
First we get the first day of current quarter:
SELECT DATEADD(QQ, DATEDIFF(QQ, 0, GETDATE()),0)
The rest is easy as we just need to go one month back.
SELECT DATEADD( MM, -1, DATEADD(QQ, DATEDIFF(QQ, 0, GETDATE()),0))
August 22, 2014 at 2:38 pm
Luis,
Thank you for your quick response. I'll play around with the dates to get better understanding. Thanks again.
Amol
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply