Get the number of days between two dates in Oracle, inclusive of the dates

前端 未结 1 1791
自闭症患者
自闭症患者 2020-12-07 01:04

I want to get total number of days between two provided dates. I\'ve tried the below query but didn\'t get the exact different; the last date is not being included.

相关标签:
1条回答
  • 2020-12-07 01:26

    In Oracle substracting two dates returns the number of days between two dates.
    A minus operator works in the same way as for numbers:

    20 - 20 = 0   ===>      2013-05-20  -  2013-05-20 = 0
    25 - 20 = 5   ===>      2013-05-25  -  2013-05-20 = 5
    

    If you want to include last number or last date, you need to add 1:

    20 - 20 + 1 = 1   ===>      2013-05-20  -  2013-05-20  + 1 = 1
    25 - 20 + 1 = 6   ===>      2013-05-25  -  2013-05-20  + 1 = 6
    
    0 讨论(0)
提交回复
热议问题