Differences between SYSDATE and format 'DD-MMM-YY' in Oracle PL/SQL

I would like to clarify why SYSDATE appears to differ from a date formatted as 28-APR-18, with the assumption that SYSDATE refers to April 28, 2018.

While debugging a small script of mine, I encountered several errors and traced them back to the way the tables were populated, specifically using the ‘DD-MMM-YYYY’ format while comparing it to SYSDATE.

To investigate this, I executed the following code to compare the two:

DECLARE
   date1 DATE;
   date2 DATE;
BEGIN
   date1 := SYSDATE;
   date2 := '27-APR-18';

   IF date1 = date2 THEN
     DBMS_OUTPUT.PUT_LINE('Match found!');
   ELSE
     DBMS_OUTPUT.PUT_LINE('No match!');
     DBMS_OUTPUT.PUT_LINE(SYSDATE);
     DBMS_OUTPUT.PUT_LINE('27-APR-18');
   END IF;
END;

Running this resulted in unexpected output:

No match!
27-APR-18
27-APR-18

PL/SQL procedure successfully completed.

Given that both variables are of DATE type, shouldn’t they be the same? I appreciate your assistance!

it’s coz sysdate includes current time wheras ‘27-APR-18’ has no time. they can’t match bcoz sysdate holds date plus time. use trunc(sysdate) to chop off the time part if u just wanna compare dates. Hpe this helps!