This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input date and expected output to find the first day of Quarter of year
Input Date Date:
1 |
'2017-09-08' |
Expected output:
1 2 3 |
QuarterOfDay ------------ 2017-07-01 |
Solution:
1 2 3 4 5 6 7 8 9 10 |
DECLARE @InputDate DATE = '2017-09-08' DECLARE @OutputDate DATE SELECT @OutputDate = CAST(YEAR(@InputDate) AS VARCHAR(4)) + CASE WHEN MONTH(@InputDate) IN (1,2,3) THEN '/01/01' WHEN MONTH(@InputDate) IN (4,5,6) THEN '/04/01' WHEN MONTH(@InputDate) IN (7,8,9) THEN '/07/01' WHEN MONTH(@InputDate) IN (10,11,12) THEN '/10/01' END SELECT @OutputDate AS QuarterOfDay |
Please try the different solution for this puzzle and share it via comment...