Skip to content
Advertisement

Get first and last 6 months in year with timestamp in SQL [closed]

I need to create first and last 6 months in a year, not considering from current date:

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
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement