Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:27:38+00:00 2026-06-13T18:27:38+00:00

Is there any tricky way to format seconds like hours:minutes:seconds. For example, 3660 seconds

  • 0

Is there any tricky way to format seconds like hours:minutes:seconds. For example,

3660

seconds will be displayed as

01h 01m 00s

or

01:01:00

I am aware of the standard way of doing this:

  1. Divide all seconds on 3600 to get the hours
  2. Divide the rest seconds on 60 to get the minutes
  3. The rest are the seconds

I met the following issues:

  1. I am not able to create separate function that do this.

  2. My code is in view using several CTEs. So, variables can be declare
    using the CTEs only.

  3. I am not able to use the standard solution because I will have
    results bigger then one day – How to convert Seconds to HH:MM:SS using T-SQL
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:27:40+00:00Added an answer on June 13, 2026 at 6:27 pm
    SELECT Seconds, 
        RIGHT('00'+CONVERT(VARCHAR(10),Seconds/3600),2)  
        +':' 
        + RIGHT('00'+CONVERT(VARCHAR(2),(Seconds%3600)/60),2) 
        +':' 
        + RIGHT('00'+CONVERT(VARCHAR(2),Seconds%60),2) AS [HH:MM:SS] 
    FROM table1
    

    Result:

    Seconds HH:MM:SS
    3660 01:01:00
    3800 01:03:20
    4200 01:10:00
    600 00:10:00
    60 00:01:00
    86400 24:00:00
    86800 24:06:40

    See this SQLFiddle


    Update

    The above query works fine if the total number of hours are less than 100 i.e. (99:59:59). If you need more than that you can use the following query:

    SELECT 
        Seconds,
        CASE Seconds/3600 
        WHEN 0 THEN RIGHT('00'+CONVERT(VARCHAR(10),Seconds/3600),2) 
        ELSE CONVERT(VARCHAR(10),Seconds/3600) END
        +':' 
        + RIGHT('00'+CONVERT(VARCHAR(2),(Seconds%3600)/60),2) 
        +':' 
        + RIGHT('00'+CONVERT(VARCHAR(2),Seconds%60),2) AS [HH:MM:SS]
    FROM table1
    

    Result:

    Seconds HH:MM:SS
    3660 1:01:00
    3800 1:03:20
    4200 1:10:00
    600 00:10:00
    60 00:01:00
    9999930 2777:45:30
    359999 99:59:59
    360000 100:00:00
    86800 24:06:40

    See this SQLFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any tricky way to implement a set data structure (a collection of
Is there any way I can set a formatter on models that will convert
Is there any way to get info like progress from another process? What I'm
Is there any simple way to create a column in MS SQL that will
Is there any tricky way to use Java reserved words as variable, method, class,
Should I merge those tables into one table? Is there any tricky alternative? Table
Inspired by this question , I'd like to know whether there is any trick
Is there any way in Notepad++ (or even with another tool) to change the
I've started looking at jQuery's built-in tabs functionality here: http://docs.jquery.com/UI/Tabs Is there any way
Is there any way to reorder or manipulate a set of inputs before posting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.