Search code examples
db2

Query DB2 Timestamp column by date only


Apologies if that question has an answer elsewhere, but I couldn't find anything matching exactly my problem. I have a timestamp column. Now I want to query that column for all rows matching a given date (day) only. I tried

SELECT * FROM MyTable WHERE created = '2024-02-12'

but that gives just a blank result. So, is there a way to search a timestamp column just by date (or time, respectively) portions?


Solution

  • You need to convert your column from Timestamp to Date :

    SELECT * 
    FROM MyTable 
    WHERE DATE(created) = '2024-02-12'