Skip to content
Advertisement

Need output by combining DATEDIFF(hh,StartTime,EndTime) + ‘Minutes’ in SQL Server

When running this query, I need output by combining

DATEDIFF(mm, StartTime, EndTime) + 'Minutes'

I’m getting this error

Conversion failed when converting the varchar value ‘Minutes’ to data type int

I need to achieve the output like 15 Minutes.

(15 represents the difference between StartTime and EndTime)

Advertisement

Answer

DATEDIFF function returns a INT values. So you need to CAST it to a string.

Try something like

SELECT CAST(DATEDIFF(mm,StartTime, EndTime) AS NVARCHAR(2)) + 'Minutes'

Obviously you can use other destination string type like charnchar etc… And use the CONVERT function instead of CAST.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement