I am trying to convert a PostgreSQL query to a T-SQL query, and I can not get the syntax correct for this PostgreSQL line:
ROUND(CAST((CURRENT_DATE - setupdate) AS decimal) /365,1) AS RetentionYears
When converting it to T-SQL, I have tried this
ROUND(CAST((GETDATE() - setupdate) AS Decimal) / 365, 1) AS RetentionYears
But when I run that I get the error
Msg 402, Level 16, State 1, Line 43
The data types datetime and date are incompatible in the subtract operator.
What would be the proper way to write that statement in T-SQL?
question from:
https://stackoverflow.com/questions/65866806/subtracting-dates-in-sql-server 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…