File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date comparision in SQL from timestamp

 
Nicolas Flammel
Ranch Hand
Posts: 32
  • 0
  • 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
  • 0
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic