Search code examples
sql-serverdatediff

Compare Time for two different columns and create third column which shows the difference in time


Hi i have two columns with n number of rows of time in 24 hour format.

I want to compare the time for each row, which means entire Column1 compared with Column2 = result_Column3(time diff for both the columns)


Solution

  • You can update your result_Column3 as,

    UPDATE tblData SET result_Column3 = CONCAT((DATEDIFF(Minute,Column1,Column2)/60),':',(DATEDIFF(Minute,Column1,Column2)%60))