Results 1 to 3 of 3

Thread: Time taken

  1. #1
    Join Date
    Sep 2002
    Posts
    218

    Time taken

    Cast(Datediff(hh,@StartTime,@EndTime) AS VARCHAR(20))+ '-Hrs ' +
    Cast(Datediff(mi,@StartTime,@EndTime) AS VARCHAR(20))+ '-Mins & '+
    Cast(Datediff(ss,@StartTime,@EndTime) AS VARCHAR(20))+ '-Secs to Load'

    This gives you sometimes 807 secs....How can I can it to give me hrs, minutes and secs properly

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    declare @starttime datetime
    declare @endtime datetime
    set @starttime ='2005-07-01 10:00:00'
    set @endtime = '2005-07-01 11:13:27'

    select cast(Datediff(ss,@StartTime,@EndTime)/60/60 as varchar(20))+'-Hrs '+
    cast(Datediff(ss,@StartTime,@EndTime)/60 -(Datediff(ss,@StartTime,@EndTime)/60/60 *60)as varchar(10))+ '-Mins & '+
    cast(Datediff(ss,@StartTime,@EndTime)- (Datediff(ss,@StartTime,@EndTime)/60 *60) AS VARCHAR(20))+ '-Secs to Load'

    --result
    1-Hrs 13-Mins & 27-Secs to Load

  3. #3
    Join Date
    Dec 2004
    Posts
    502
    Or, without the fancy presentation stuff:

    SELECT CONVERT(varchar, DATEADD(ss, DATEDIFF(ss, @starttime, @endtime), 0), 108)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •