Reputation: 923
I wanted to find the number of days between two dates in oracle.So,I tried:
select to_date('03/09/2011','MM/DD/YYYY') -to_date('03/09/2010','MM/DD/YYYY') "Days" from dual;
the output is 365.Its ok ,but when I tried:
select to_date(sysdate,'mm/dd/yyyy') -to_date('03/09/2010','MM/DD/YYYY') "Days" from dual;
i got error as:
ORA-01858: a non-numeric character was found where a numeric was expected
And also suppose ,if I calculate the no of days between 2010 and sysdate then the year which contains leap year will be also handled by oracle itself?
Upvotes: 1
Views: 8272
Reputation: 7416
you can try this: (sysdate is already date format so you can use like this)
select trunc(sysdate) -to_date('03/09/2010','MM/DD/YYYY') "Days" from dual;
Upvotes: 3