Operand Type Clash: Date Is Incompatible With Int

Recently, as a SQL Server developer, I was required to retrieve yesterday’s Date. I was working on that requirement. I was using the CAST() for this purpose. After executing a SQL query using the CAST() function, I encountered this error. In this article, we will discuss how to fix the error operand type clash date is incompatible with int.

Fix: Operand Type Clash: Date Is Incompatible With Int

I executed the following query to retrieve yesterday’s date in SQL Server.

SELECT CAST(CURRENT_TIMESTAMP AS Date) - 1 AS YesterdayDateOnly

After executing the above query, I encountered the error shown in the screenshot below.

Operand Type Clash: Date Is Incompatible With Int

Solution

Now, let’s discuss multiple solutions to resolve this error.

Solution-1

Here, we will use the DATEADD() function along with the CAST() function to obtain the required output.

SELECT DATEADD(day, -1, CAST(CURRENT_TIMESTAMP AS DATE)) AS YesterdayDateOnly

Or,

SELECT DATEADD(day, -1, CAST(GETDATE() AS DATE)) AS YesterdayDateOnly

After executing the above query, I got the expected output as per the screenshot below.

sql operand type clash date is incompatible with int
sql date is incompatible with int

Or, you can also use the below query for the same output.

SELECT CAST(DATEADD(DAY, -1, GETDATE()) AS DATE) AS YesterdayDateOnly

We successfully obtained the desired output, as shown in the screenshot below.

date is incompatible with int in sql server

Solution-2

We can execute the query below to retrieve yesterday’s date with time.

SELECT CAST(CURRENT_TIMESTAMP AS datetime) - 1 AS YesterdayDatewithtime

After executing the above query, we got the expected output as shown in the screenshot below.

Date Is Incompatible With Int

Alternatively, you can use the query below without the CAST() function.

SELECT CURRENT_TIMESTAMP - 1 AS YesterdayWithTime

Refer to the screenshot below, which displays the expected output.

operand clash date is incompatible with int

Video Tutorial

You may also like the following articles.