locked
Convert MySQL query to Sql query RRS feed

  • Question

  • HI Team,

    Iam in the process of modifying the MySQL queries to SQL queries and i wanted to convert the following MySQL Datetime function to Sql Server and appreciate your help on the same:

    TIME_FORMAT(timediff(shift.formattedEndTime, shift.formattedStartTime),'%h')

    Thanks,

    Ram


    Thursday, April 13, 2017 1:16 PM

Answers

  • You are looking for the time difference in hours between two dates.

    select datediff(hh, shift.formattedStartTime, shift.formattedEndTime) from shift

    Here we are getting the difference in hours between the start time and end time.

    Thursday, April 13, 2017 1:52 PM

All replies

  • Hello Ram,

    Which Version of SQL Server are you using? Since 2012 you can use the FORMAT (Transact-SQL) function for it


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Thursday, April 13, 2017 1:21 PM
  • Thanks for the quick reply olaf could you please convert and provide me the line of code if possible

    Regards,

    Ram

    Thursday, April 13, 2017 1:32 PM
  • You are looking for the time difference in hours between two dates.

    select datediff(hh, shift.formattedStartTime, shift.formattedEndTime) from shift

    Here we are getting the difference in hours between the start time and end time.

    Thursday, April 13, 2017 1:52 PM
  • Thanks a lot for doing the needful Hilary Cotter
    Thursday, April 13, 2017 2:19 PM