Different results for Date range

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zdtic03
    New Member
    • Sep 2015
    • 1

    Different results for Date range

    I have a query that counts records between 2 dates.
    When I use
    to_char(LAST_CN T_DATE_TIME,'YY YY/MM/DD') between
    '2015/09/01' and
    '2015/09/23'
    result is 11405

    When I use
    LAST_CNT_DATE_T IME between
    to_date('2015/09/01','YYYY/MM/DD') and
    to_date('2015/09/23','YYYY/MM/DD')

    result is 9389
    I am more apt to use the first
    sometimes the results are the same
    Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You're not accounting for the time.

    to_date('2015/09/01','YYYY/MM/DD') and to_date('2015/09/23','YYYY/MM/DD')
    have a time value of midnight, 00:00:00.000000 . LAST_CNT_DATE_T IME with a time value after midnight on 9/23 don't get counted because it's outside the range you're looking for.

    You should truncate the time portion of LAST_CNT_DATE_T IME before trying to filter it on your date range.

    Comment

    Working...