Wrong value when substracting dates

I guess the answer is simple, but I can’t really figure it out. My goal is to count the days between two dates for every record in the table “ord”. The dates are stored in columns with DATE datatype.

I do the substraction ‘SELECT date_shipped – date_ordered AS ‘DAYS’ FROM ord;’, but the answer is wrong. Let’s say I have the date ’92/09/17′ as date_shipped and ’92/08/28′ as date_ordered and the result is ’10’, which is not true.

When I do it manually, as ‘SELECT TO_DATE(’92/09/17’, ‘YY/MM/DD’) – TO_DATE(’92/08/28′,’YY/MM/DD’) AS ‘DAYS’ FROM dual;’ (or ord), the result is ’20’, which is correct.

Why is that, and how can I fix it, so it will get the correct result when fetching dates from the table? Thank you.

submitted by /u/Gilgameus
[link] [comments]


Go to Source of this post
Author Of this post: /u/Gilgameus
Title Of post: Wrong value when substracting dates
Author Link: {authorlink}