I am trying to get Which day of the quarter when you give a current date.
For Example if i give 01/25/2012 then the output should be 25. Since it is the 25th day of the quarter.
Similarly if i give 02/01/2012 it should give 32 as output.
I am able to get the first day of the quarter but not able to get which day it is in the quarter.
I did something like this:
SELECT FirstDayOfQuarter = CONVERT(DATE, dateadd(qq, datediff(qq,0, GETDATE()),0))
Can anyone help me?
Find the first day of the quarter:
DATEADD(q, DATEDIFF(q, 0, @TestDate) ,0)
Then find the difference in days with your given date.
DECLARE @TestDate DATETIME;
SET @TestDate = 'January 25, 2012';
SELECT DATEDIFF(dd, DATEADD(q, DATEDIFF(q, 0, @TestDate),0), @TestDate) + 1;
You are almost there.
SELECT DateDiff(dd,CONVERT(DATE,
dateadd(qq, datediff(qq,0, GETDATE()),0)),getDate())+1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With