Oracle Time Difference between SYSDATE and Date From Column Oracle Time Difference between SYSDATE and Date From Column oracle oracle

Oracle Time Difference between SYSDATE and Date From Column


This expression:

to_date(SYSDATE, 'yyyy-MM-dd') 

doesn't make sense. SYSDATE is already a date. So, this expression converts SYSDATE to a string, using whatever local settings are on your system. Then, it converts that result to a date, using the format 'yyyy-MM-dd'. For many values of the local settings, this would simply fail.

If you want the difference, then do something like this:

SELECT (trunc(SYSDATE) - trunc(LoginDate)) as differenceFROM LOGINRECORDSWHERE LoginRecordId = '1000001';

Note that in Oracle, the DATE data type has a time component, hence the use of trunc(). If you know that LoginDate has no time component, then that part does not require trunc().