• GSquared (4/24/2009)


    Before you start stuffing the string, make sure that times before 10 AM are stored with leading zeroes. If not, you might have a problem when 9:00 AM tries to turn into the hour 90.

    Hmm, good point.

    How about this?

    select convert(char(8),

    convert(datetime,

    convert(datetime, stuff(stuff(right('0' + '154040',6),3,0,':'),6,0,':')) -

    convert(datetime, stuff(stuff(right('0' + '133737',6),3,0,':'),6,0,':'))),

    108)

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2