I have a table with all days (1-31) of 2021 and 2022. I want to filter out the last days (24.12 - 31.12) in every year.
I tried following:
SELECT DATE_column
FROM TABLE_A
WHERE CONCAT(DATEPART(dd,DATE_column), DATEPART(mm,DATE_column)) not in (2412, 2512,2612,2712,2812,2912,3012, 3112 )
Yes it does working. But I wonder whetever there are a more simple method.
CodePudding user response:
SELECT DATE_column FROM TABLE_A
WHERE (MONTH(DATE_column) = 12 AND DAY(DATE_column) < 24) or MONTH(DATE_column) < 12
CodePudding user response:
Something like this?
DELETE FROM your_table
WHERE MONTH(DATE_column) = 12 AND DAY(DATE_column) >= 24
CodePudding user response:
SELECT *
FROM table_name
WHERE (YEAR(date_column) = 2021 AND MONTH(date_column) != 12) OR (YEAR(date_column) = 2022 AND MONTH(date_column) != 12) OR (MONTH(date_column) = 12 AND DAY(date_column) < 24)
Note: "date_column" should be replaced by actual date column name in your table.