0

I am using this query:

  SELECT ts as "TimeStamp", 
         stat as "Status"
    FROM myTable
   WHERE stat = 'O'
     AND source = 'Source1'
     AND ts BETWEEN TO_TIMESTAMP('2013-10-05','yyyy-mm-dd') AND
                    TO_TIMESTAMP('2013-10-06','yyyy-mm-dd') 

And also tried:

  SELECT ts as "TimeStamp", 
         stat as "Status"
    FROM myTable
   WHERE stat = 'O'
     AND source = 'Source1'
     AND ts >= TO_TIMESTAMP('2013-10-05','yyyy-mm-dd') AND ts <
                    TO_TIMESTAMP('2013-10-06','yyyy-mm-dd') 

It returns 0 records, but if I do

  SELECT ts as "TimeStamp", 
         stat as "Status"
    FROM myTable
   WHERE stat = 'O'

I can clearly identify 5 records. Apparently the TO_TIMESTAMP is not working properly I am hoping someone might be able to help identify the proper fix

Edit: To clarify, I only want the timeframe for 10/5 not including 10/6 Sorry pasted wrong results Also the field is of type TIMESTAMP(6)

2 Answers 2

4

Because the TO time stamp has time even though you're not specifying. So it is selecting only up to the very beginning of the lat day. Either specify time 23:59:59 and subseconds as required, or do less than the next day.

...
AND ts >= TO_TIMESTAMP('2013-10-05','yyyy-mm-dd') 
AND ts <  TO_TIMESTAMP('2013-10-07','yyyy-mm-dd') 
Sign up to request clarification or add additional context in comments.

1 Comment

Looking, but I do notice in your edited post you have the second clause as less than 2013-10-06. If that was the try then it would still be wrong. Needs to be less than the next day, so notice my example uses 2013-10-07.
0

Try: AND ts BETWEEN TO_DATE('2013-10-05','YYYY-MM-DD') AND TO_DATE('2013-10-06','YYYY-MM-DD')

And mind that it will get you results from the 10-05 at 00:00:00 to the 10-06 at 00:00:00 If you don't specify the HH MI SS mask.

Date masks are case sensitivve and TO_DATE will work better.

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.