• pspkshah (5/29/2015)


    Hello friends,

    how can I get time difference of the following record please help,

    STARTTIME ENDTIME

    3:30 PM 4:30PM

    7:30 PM 8:30PM

    I have tried it by below query,

    SELECT CONVERT(TIME,STARTTIME,108) - CONVERT(TIME,ENDTIME,108) FROM BATCH_MASTER

    but it gives following error message

    Operand data type time is invalid for subtract operator.

    You should start your own thread instead of hijacking another thread that is 4 years old.

    When you want to do math on date or datetime you should use DATEADD. You would do yourself a huge favor by using the time datatype instead of storing time information in a varchar column.

    --EDIT--

    I see that you did in fact start your own thread for this. http://www.sqlservercentral.com/Forums/Topic1689898-391-1.aspx

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/