0

I am trying filter based on a date range that should only go to 2023-01-01 (or first day of the next year) that corresponds to a field and it's date range (current and previous dates).

My current filter in the where statement includes this but unsure how to set the first of the next year.

select * from df
where year(split_start_date) = year(dateadd(year,+1,current_date()))

I am able to filter based on year out of 'split_start_date' but want to set a cutoff to the first day of the next year.

Dinho
  • 704
  • 4
  • 15
  • Your query is not SARGable btw. Also, you don't need to do `year(split_start_date)` (which is what ruins SARGability). – Dai Oct 07 '22 at 19:14
  • What do you mean by "set a field", btw? `SELECT` queries don't edit any data... – Dai Oct 07 '22 at 19:14
  • Basically I want to only filter date ranges that correspond to split_start_date up to 2023-01-01 if that makes sense? – Dinho Oct 07 '22 at 19:21
  • 1
    You essentially want `WHERE date <= '2023-01-01'`. You can dynamically create that date (if it's always going to be the first date of the first month) like `WHERE date <= CONCAT(YEAR(CURRENT_DATE)+1, "-01-01")`. Or if you have separate `year`, `month`, and `day` fields: `WHERE year <= CONCAT(YEAR(CURRENT_DATE)+1) AND month = 1 AND day = 1`. – WOUNDEDStevenJones Oct 07 '22 at 19:27

0 Answers0