I need to create first and last 6 months in a year, not considering from current date:
x
select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-6, 0)
I used this, but this gives the first date of 6 months before
Advertisement
Answer
DATEFROMPARTS
function can be used for that:
SELECT
DATEFROMPARTS(YEAR(GETDATE()),1,1) AS beginningOfYear,
DATEFROMPARTS(YEAR(GETDATE()),6,1) AS midOfYear