Eclipse or SUNrise...

Eclipse or SUNrise...
...JAVA for sure

Tuesday, October 21, 2008

DB2, SQL and Timestamp

I found it quite difficult to figure out how to write a select in DB2, which would contain a proper time-condition. I wanted to query for some data, inserted couple of days ago. Google showed me many Internet forums, on which people complained that they had problems with to_date() function.

Well, the to_date() function in DB2 is generally used for formating the output of the select statements. For the condition you should use TIMESTAMP() or DATE() functions, for example:

SELECT something FROM table WHERE INPUT_DATE >= TIMESTAMP('2008-10-14 18:03:00.0') AND INPUT_DATE <= TIMESTAMP('2008-10-21 18:03:14.0')

No comments: