September 6, 2013 at 12:44 am
Hi,
My requirement is,I want preceding 7th date of any given date.
For example,
1)Declare @AsonDate As datetime = '2013-08-31'
Then my output should be '2013-08-07'
2)Declare @AsonDate As datetime = '2013-09-06'
Then my output should be '2013-08-07'
Kindly help me!!
Thanks in Advance!!
September 6, 2013 at 12:53 am
Here you go:
DECLARE @AsonDate DATETIME = '2013-08-11';
SELECT CASE WHEN DAY(@AsonDate) < 7
THEN DATEADD(d,6,DATEADD(d,-(DAY(DATEADD(m,-1,@AsonDate))-1),DATEADD(m,-1,@AsonDate)))
ELSE DATEADD(d,6,DATEADD(d,-(DAY(@AsonDate) - 1),@AsonDate))
END;
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
September 6, 2013 at 12:59 am
Thanks!!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy