INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Date and time Tips and tricks

Converting Seconds to HH:MM:SS Revisited by AlexCuse
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 Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close