Search code examples
sqloracledate-arithmetic

Using less than in Oracle to compare date can not get expected answer


Table Employee:

CREATE TABLE Employee(
    ID CHAR(10) PRIMARY KEY,
    SSN CHAR(15) NOT NULL,
    FNAME CHAR(15),
    LNAME CHAR(15),
    DOB DATE NOT NULL
);
INSERT INTO Employee VALUES('0000000001','078-05-1120','George','Brooks', '24-may-85');
INSERT INTO Employee VALUES('0000000002','917-34-6302','David','Adams', '01-apr-63');
INSERT INTO Employee VALUES('0000000003','078-05-1123','Yiling','Zhang', '02-feb-66');
INSERT INTO Employee VALUES('0000000004','078-05-1130','David','Gajos', '10-feb-65');
INSERT INTO Employee VALUES('0000000005','079-04-1120','Steven','Cox', '11-feb-79');
INSERT INTO Employee VALUES('0000000006','378-35-1108','Eddie','Gortler', '30-may-76');
INSERT INTO Employee VALUES('0000000007','278-05-1120','Henry','Kung', '22-may-81');
INSERT INTO Employee VALUES('0000000008','348-75-1450','Harry','Leitner', '29-oct-85');
INSERT INTO Employee VALUES('0000000009','256-90-4576','David','Malan', '14-oct-88');
INSERT INTO Employee VALUES('0000000010','025-45-1111','John','Brooks', '28-nov-78');
INSERT INTO Employee VALUES('0000000011','025-59-1919','Michael','Morrisett', '04-nov-85');
INSERT INTO Employee VALUES('0000000012','567-45-2351','David','Nelson', '10-nov-54');
INSERT INTO Employee VALUES('0000000013','100-40-0011','Jelani','Parkes', '20-dec-44');

When I use queries like:

SELECT * FROM EMPLOYEE WHERE DOB < '01-jan-80';

I did not get the record of '0000000013','100-40-0011','Jelani','Parkes', '20-dec-44'. I think that might be a date format problem, but I am not sure. Anyone have an idea? Thanks!


Solution

  • you provided year in 2 digit format(rr)

    then year < 50 will be 20xx and year > 50 will be 19xx

    means 56 will be 1956 44 means 2044

    that's why it was excluded