INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • Turn Off Ad Banners
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...Keep up the good work - excellent site - i'd been looking for something like this for ages !..."

Geography

Where in the world do Tek-Tips members come from?

Microsoft SQL Server: Programming FAQ

Date and time Tips and tricks

Converting Seconds to HH:MM:SS Revisited
Posted: 19 Jan 07 (Edited 6 Aug 07)

As pointed out by a helpful member (and in my estimation date/time wizard) I was going about this all wrong.  The easiest (and IMO best) way to do this is as follows:

CODE

create function SecTimeDay (@sec integer)
returns varchar(19)
as
begin

declare @DayTime varchar(19)

/* Calculate # of days and display if necessary */
Select @DayTime = Case When @Sec >= 86400
                Then Convert(VarChar(5), @Sec/86400)
                + ' days '
                Else ''
                End
/* Add HH:MM:SS to number of days (or ') for output */
       + Convert(VarChar(8), DateAdd(Second, @Sec, 0), 108)

return @DayTime

end

This function performs much better than the one I initially posted, and it also reports days.

Hope this one is helpful to someone.

Alex



Back to Microsoft SQL Server: Programming FAQ Index
Back to Microsoft SQL Server: Programming Forum
My FAQ Archive
Email This FAQ To A Friend

My Archive