-- create CREATE TABLE EMPLOYEE ( empId int, from_datetime DATETIME default null, to_datetime DATETIME default null ); -- insert INSERT INTO EMPLOYEE VALUES (0001, '2020-02-29 00:00:00', '2021-02-28 00:00:00'); INSERT INTO EMPLOYEE VALUES (0002, '2019-03-01 00:00:00', '2021-02-28 00:00:00'); -- fetch SELECT empId, datediff(month, from_datetime, to_datetime) as months, datediff(day, from_datetime, to_datetime) as days FROM EMPLOYEE; GO