1


I have stored TIMESTAMP attribute in the database in the following format:
11/17/2014 3:00:00 PM
11/17/2014 4:00:00 PM
etc...
I am trying to query for all records ( I stored 30 days) where hour is 3:00 PM.

Select * from DaysTb where timeOfday =to_date('11/17/2014 3:00:00 PM','mm/dd/yyyy hh12:00')

however, my query is incorrect. Googling did not help me to find an answer. I would appreciate some guidance. Thanks.

2
  • Do you mean the timestamp attribute is stored as a STRING in the database? or as a true TIMESTAMP data type? If it is the latter (and I hope it is), it is NOT stored in the format you show - that is a string format, not a timestamp "format." Also, when you say 3:00 PM, do you mean exactly 3:00:00, or any time between 3:00:00 and 3:59:59? By the way, to find out the data type of your columns, you can try DESCRIBE DAYSTB if you use sqlplus (or Toad or SQL Developer). Commented Apr 22, 2016 at 15:42
  • The data are stored as TIMESTAMP. With my co-worker help, I used Extract with HOUR and was able to query all the records within a month where hour equals to 3:00 PM. Commented Apr 23, 2016 at 18:48

1 Answer 1

1

Here is the correct Oracle SQL statement

select *  from yourTableName where 
EXTRACT(HOUR FROM data_date ) = 15;

It returns all the records with 15:00 o'clock stamp.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.