Search code examples
sqloracle-databasedatedate-conversion

Oracle: date to half-year


What I need is a conversion from a date to the half-year:

  • 29.06.2018 -> 1
  • 01.05.2018 -> 1
  • 01.07.2018 -> 2
  • 15.10.2018 -> 2

I did not find anything like that here Round and Truncate in Oracle

So, no built-in function exists indeed? I'm quite perplexed because that's not a very rare use case. Or have I missed something?


Solution

  • Just use a case expression:

    select (case when extract(month from datecol) <= 6 then 1
                 else 2
            end) as half_year