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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:17:01+00:00 2026-05-12T16:17:01+00:00

I have a table with two DATETIME columns: Column1 Column2 1/1/1900 12:20:45 1/1/1900 23:22:25

  • 0

I have a table with two DATETIME columns:

Column1              Column2
1/1/1900 12:20:45    1/1/1900 23:22:25
1/1/1900 09:00:00    1/1/1900 18:10:30
…                    …

(Times are in the format HH:MM:SS.)

I want to take a total of column 1 and total of column 2. If the table had only the two rows shown above, the expected outcome would be:

Column1              Column2 
1/1/1900 21:20:45    1/1/1900 41:32:55

Note that hours, minutes, and seconds should not exceeded 60.

How do I sum these columns in SQL Server 2000?

  • 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-05-12T16:17:01+00:00Added an answer on May 12, 2026 at 4:17 pm

    this will give you what you are after:

    CREATE TABLE #Times
    (
         Column1 datetime
        ,Column2 datetime
    )
    
    INSERT INTO #Times VALUES ('1/1/1900 12:20:45',    '1/1/1900 23:22:25')
    INSERT INTO #Times VALUES ('1/1/1900 09:00:00',    '1/1/1900 18:10:30')
    
    SELECT
         CONVERT(varchar(10),dateadd(day,datediff(day,0,dt2.MinColumn1),0),101)
             +' '
             +CASE WHEN TotalSecondsColumn1/3600>60 then '60' ELSE CONVERT(varchar(2),TotalSecondsColumn1/3600) END
             +':'
             +CASE WHEN (TotalSecondsColumn1-(TotalSecondsColumn1/3600*3600))/60 >60 then '60' ELSE CONVERT(varchar(2),(TotalSecondsColumn1-(TotalSecondsColumn1/3600*3600))/60) END
             +':'
             +CASE WHEN TotalSecondsColumn1-((TotalSecondsColumn1/3600*3600)+(((TotalSecondsColumn1-(TotalSecondsColumn1/3600*3600))/60)*60)) >60 then '60' ELSE CONVERT(varchar(2),TotalSecondsColumn1-((TotalSecondsColumn1/3600*3600)+(((TotalSecondsColumn1-(TotalSecondsColumn1/3600*3600))/60)*60))) END
         AS Column1
        ,CONVERT(varchar(10),dateadd(day,datediff(day,0,dt2.MinColumn2),0),101)
             +' '
             +CASE WHEN TotalSecondsColumn2/3600>60 then '60' ELSE CONVERT(varchar(2),TotalSecondsColumn2/3600) END
             +':'
             +CASE WHEN (TotalSecondsColumn2-(TotalSecondsColumn2/3600*3600))/60 >60 then '60' ELSE CONVERT(varchar(2),(TotalSecondsColumn2-(TotalSecondsColumn2/3600*3600))/60) END
             +':'
             +CASE WHEN TotalSecondsColumn2-((TotalSecondsColumn2/3600*3600)+(((TotalSecondsColumn2-(TotalSecondsColumn2/3600*3600))/60)*60)) >60 then '60' ELSE CONVERT(varchar(2),TotalSecondsColumn2-((TotalSecondsColumn2/3600*3600)+(((TotalSecondsColumn2-(TotalSecondsColumn2/3600*3600))/60)*60))) END
         AS Column1
        FROM #Times t
            INNER JOIN (SELECT
                             SUM(DATEDIFF(second,CONVERT(datetime,LEFT(CONVERT(char(23),Column1,121),10)),Column1)) AS TotalSecondsColumn1
                            ,SUM(DATEDIFF(second,CONVERT(datetime,LEFT(CONVERT(char(23),Column2,121),10)),Column2)) AS TotalSecondsColumn2
                            FROM #Times
                       ) dt ON 1=1
            INNER JOIN (SELECT
                             MIN(Column1) AS MinColumn1
                            ,MIN(Column2) AS MinColumn2
                            FROM #Times
                       ) dt2 ON 1=1
        WHERE t.Column1=dt2.MinColumn1
    

    OUTPUT:

    Column1             Column1
    ------------------- -------------------
    01/01/1900 21:20:45 01/01/1900 41:32:55
    
    (1 row(s) affected)
    

    However, this will accurately sum the times, incrementing the day, month, and year as well:

    SELECT
         DATEADD(second,dt.TotalSecondsColumn1,dateadd(day,datediff(day,0,dt2.MinColumn1),0)) AS Column1
        ,DATEADD(second,dt.TotalSecondsColumn2,dateadd(day,datediff(day,0,dt2.MinColumn2),0)) AS Column2
        FROM #Times t
            INNER JOIN (SELECT
                             SUM(DATEDIFF(second,CONVERT(datetime,LEFT(CONVERT(char(23),Column1,121),10)),Column1)) AS TotalSecondsColumn1
                            ,SUM(DATEDIFF(second,CONVERT(datetime,LEFT(CONVERT(char(23),Column2,121),10)),Column2)) AS TotalSecondsColumn2
                            FROM #Times
                       ) dt ON 1=1
            INNER JOIN (SELECT
                             MIN(Column1) AS MinColumn1
                            ,MIN(Column2) AS MinColumn2
                            FROM #Times
                       ) dt2 ON 1=1
        WHERE t.Column1=dt2.MinColumn1
    

    OUTPUT:

    Column1                 Column2
    ----------------------- -----------------------
    1900-01-01 21:20:45.000 1900-01-02 17:32:55.000
    
    (1 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table contains various columns including two DateTime column, Start and End
I want to have one table with two TIMESTAMP columns. One column to keep
I have a table called Sessions with two datetime columns: start and end. For
I have a table with one row and two columns- int 'version', datetime 'updated'
Please help me: I have two columns in mysql table - date1 (datetime) and
If I have a table that (among other columns) has two DATETIME columns, how
Say I have an MSSQL table with two columns: an int ID column that's
I have a table with two DATETIME columns. One of them is never NULL,
i have a table with two columns first column is a (currentdate)timestamp and the
I have two datetime columns in a table, and I would like to select

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.