Recently, I was working on a requirement to calculate the days difference using the subtraction operator along with a SQL script, and after executing that script, I got the error Operand data type date is invalid for subtract operator.
Operand data type date is invalid for subtract operator.
I was executing the query below for calculating the day difference.
SELECT
student_id,
full_name,
admission_date,
CAST(CAST(GETDATE() as date) - admission_date as int) AS employment_days
FROM nstudents
WHERE location IN ('New York, NY', 'Chicago, IL', 'Los Angeles', 'Houston');After executing the above query, I got the error as shown in the screenshot below.

Cause of this error
This error occurs in SQL Server because we are attempting to perform arithmetic operations directly on DATE data types, which is not permitted.
Solution
To solve this issue, we first need to convert the date datatype to datetime using the following query.
SELECT
student_id,
full_name,
admission_date,
CAST(GETDATE() - CAST(admission_date AS DATETIME) AS INT) AS employment_days
FROM nstudents
WHERE location IN ('New York, NY', 'Chicago, IL', 'Austin', 'Houston');After executing the above query, I got the error as shown in the screenshot below.

You may also like the following articles.
- SQL Error Code
- SQL Server Days Between Date and Today
- The data types datetime and date are incompatible in the subtract operator.
- Operand data type datetime2 is invalid for subtract operator.
- Operand Type Clash: Date Is Incompatible With Int
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.