Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date comparision in SQL from timestamp

 
Nicolas Flammel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to compare a Timestamp returned from Java code 2004-06-11 00:00:01.0
in a query in Oracle to a date value 2004-06-11 00:00:00.0 in the table .
I have used
select id
from table
where TIME between to_date('2004-06-09 00:00:00','yyyy-mm-dd hh:mi:ss') and to_date('2004-06-11 00:00:00','yyyy-mm-dd hh:mi:ss')

I get a message that hour can be between 1 and 12. But I want to check the time for midnight. How to format the date in SQL query...???
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use HH24 instead of HH in your format string. It's all in the Oracle documentation. But really, why don't you simply use PreparedStatement? That allows you to sidestep the entire date format minefield (and similarly for Strings, it allows you to sidestep the escape character minefield).

- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic