Recently, I was working on a requirement where I needed to calculate the days between a date and today. After executing a SQL script, I encountered the error: ‘The data types datetime and date are incompatible in the subtract operator.’
The data types datetime and date are incompatible in the subtract operator.
I was executing the below SQL script.
SELECT
employee_id,
first_name,
last_name,
hire_date,
CAST(GETDATE() - hire_date AS INT) AS employment_days
FROM employees
WHERE office_location IN ('New York', 'Chicago', 'Los Angeles', 'Houston');However, immediately after executing this script, I encountered the error shown in the screenshot below.

Reason for this error
The error happens because:
GETDATE()returns aDATETIMEdata typehire_dateis likely aDATEdata type- SQL Server doesn’t allow direct arithmetic operations between incompatible data types
Solution
Solution 1: Convert DATE to DATETIME
To fix this error, we need to convert the date to a datetime first using the below query.
SELECT
employee_id,
full_name,
hire_date,
CAST(GETDATE() - CAST(hire_date AS DATETIME) AS INT) AS employment_days
FROM nemployees
WHERE office_location IN ('New York, NY', 'Chicago, IL', 'Austin', 'Houston');After executing the above query, I got the result successfully without any error, as shown in the screenshot below.

Solution 2: Use DATEDIFF Function (Recommended)
You can also use the DATEDIFF function to achieve the expected output without any issue. We can execute the query below.
SELECT
employee_id,
full_name,
hire_date,
DATEDIFF(DAY, hire_date, GETDATE()) AS employment_days
FROM nemployees
WHERE office_location IN ('New York, NY', 'Chicago, IL', 'Los Angeles', 'Houston');After executing the above query, I got the result successfully without any error, as shown in the screenshot below.

You may also like the following articles:
- Operand data type date is invalid for subtract operator.
- Explicit conversion from data type datetime2 to float is not allowed.
- Operand data type datetime2 is invalid for the subtract operator.
- The datepart millisecond is not supported by date function dateadd for data type date.
After working for more than 15 years in the Software field, especially in Microsoft technologies, I have decided to share my expert knowledge of SQL Server. Check out all the SQL Server and related database tutorials I have shared here. Most of the readers are from countries like the United States of America, the United Kingdom, New Zealand, Australia, Canada, etc. I am also a Microsoft MVP. Check out more here.