Firebird – How to Select and Show All Tickets from Last Calendar Year

date formatfirebirdselect

It seems SQL calls varies a lot, and cannot find how to do this in Firebird, where SQL dialect is 3.

There's a table called TICKETS. This table has INSERT_TIME which is TIMESTAMP. How do I select all the tickets which has insert time year = 2016?

Best Answer

Depending on your needs, you can use:

  1. Using extract:

    select *
    from tickets
    where extract(year from insert_time) = 2016
    
  2. Using between:

    select *
    from tickets
    where insert_time between timestamp'2016-01-01 00:00:00.0' and timestamp'2016-12-31 23:59:59.99999'
    

Depending on the volume of data, and the presence of an index on insert_time or not, the second may be preferable over the first.