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 8426421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:31:50+00:00 2026-06-10T04:31:50+00:00

MySQL has a cool function sec_to_time() which converts your number of seconds to hh:mm:ss

  • 0

MySQL has a cool function sec_to_time() which converts your number of seconds to hh:mm:ss

I’ve read through the mailing lists and am basically trying to implement the following:

MySQL:
select sec_to_time(sum(unix_timestamp(enddate) - unix_timestamp(startdate))) from foo;

PostgreSQL:
select XXX(sum(date_part('epoch',enddate) - date_part('epoch',startdate))) from foo;

I just need to know what XXX is/can be. I’ve tried a lot of combinations of the documented functions .

Please let how to do this in PostgreSQL?

  • 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-10T04:31:51+00:00Added an answer on June 10, 2026 at 4:31 am

    Use to_char:

    regress=# SELECT to_char( (9999999 ||' seconds')::interval, 'HH24:MM:SS' );
      to_char   
    ------------
     2777:00:39
    (1 row)
    

    Here’s a function that produces a text formatted value:

    CREATE OR REPLACE FUNCTION sec_to_time(bigint) RETURNS text AS $$
    SELECT to_char( ($1|| ' seconds')::interval, 'HH24:MI:SS');
    $$ LANGUAGE 'SQL' IMMUTABLE;
    

    eg:

    regress=# SELECT sec_to_time(9999999);
     sec_to_time 
    -------------
     2777:00:39
    (1 row)
    

    If you’d prefer an INTERVAL result, use:

    CREATE OR REPLACE FUNCTION sec_to_time(bigint) RETURNS interval AS $$
    SELECT justify_interval( ($1|| ' seconds')::interval);
    $$ LANGUAGE 'SQL' IMMUTABLE;
    

    … which will produce results like:

    SELECT sec_to_time(9999999);
           sec_to_time       
    -------------------------
     3 mons 25 days 17:46:39
    (1 row)
    

    Don’t cast an INTERVAL to TIME though; it’ll discard the days part. Use to_char(theinterval, 'HH24:MI:SS) to convert it to text without truncation instead.

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

Sidebar

Related Questions

MySQL has a function called STR_TO_DATE, that converts a string to date . Question:
I have a MySQL table which has a product_id field (big integer) 1102330008 1102330025
I have a huge MySQL table which has its rows encoded in UTF-8 twice.
MySQL has a very nice option for INSERT statement, which is particularly helpful for
MySQL has a nice feature (although non standard) which allow to query resultsets' limit,
Hunting internationalization bugs here. Does mysql has a variable which can be set per
MySQL has a setting called 'max_allowed_packet' which is set separately for clients and servers.
I know mysql has the MIN() function pulls out the smallest value located in
I'm designing my database schema using MySQL Workbench, which is pretty cool because you
Besides INSERT/UPDATE/SELECT/DELETE MySQL has something called HANDLER . I've read that it can be

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.