Skip to content
Advertisement

How can a query select dates from only a specific academic year?

This may be simple, but I cannot figure out the correct and simplest way to query a table which contains a date col to return the rows in which the date belongs to the current academic year.

Knowing that for academic year I mean the period from the 1st of September of a year to the 31st of august of the next one, how can you obtain the right dataset from a table that look like this:

TABLE
----
Date
----
12/08/2015
15/06/2015
01/09/2015 <-
07/10/2015 <-
09/11/2015 <-
21/12/2015 <-
15/01/2016 <-
18/03/2016 <-
28/04/2016 <-
29/06/2016 <-
30/07/2016 <-
12/09/2016
23/11/2016

Advertisement

Answer

This is an Oracle equivalent of Andomar’s post –

select
   *
from
   dts
where
   case
     when extract (month from dt) < 9 then extract (year from dt) - 1
       else extract (year from dt)
         end = extract (year from sysdate)

Fiddle: http://sqlfiddle.com/#!4/75a16/1/0

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement