Home > Back-end >  Filter data from timestamp by passing only part of date in sql
Filter data from timestamp by passing only part of date in sql

Time:05-16

I want to write query to filter data set from table by only passing part of date as year & month or quarter range & year Passed value of (part of date) -> 2021-4 Or Q1-2021 But in table date has stored as 01-APR-21 1222.36643100 PM ASIA/COLOMBO

May I know how do I filter data? I filtered data from like this but this is not I want. -> Select * from A where CAST(A.startDate as DATE) like '%-APR-21'

CodePudding user response:

Maybe the EXTRACT method can be useful.

For example in your case:

Select * from A 
where EXTRACT(MONTH FROM A.startDate) = 4
AND EXTRACT(YEAR FROM A.startDate) = 2021

USAGE

SELECT EXTRACT(<PART> FROM A.startDate);
  • Related