Date Conversion

  • Good Experts, 
    Please help me to convert and  find the difference in HH:MM:SS format between the two dates and time. Below are the columns
    Step Start Time                                                  Step End Time
    2018-04-01 23:55:00.8257333                           2018-04-01 23:55:02.8569772

    Thanks

  • tmmutsetse - Wednesday, June 6, 2018 7:44 AM

    Good Experts, 
    Please help me to convert and  find the difference in HH:MM:SS format between the two dates and time. Below are the columns
    Step Start Time                                                  Step End Time
    2018-04-01 23:55:00.8257333                           2018-04-01 23:55:02.8569772

    Thanks

    Do you want to keep accuracy in your query? How much would you want? Will the difference be over 24 hours? over 31 days?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Probably the best approach will be to find the difference in seconds, then convert that to the format you need.  If you know the difference will ALWAYS be less than 24 hours, then maybe something like:
    CONVERT(VARCHAR(8), DATEADD(SECOND, DATEDIFF(SECOND, StepStartTime, StepEndTime), 0), 108)
    otherwise you'll need to build the parts of time in the string, which could get messy.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply