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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:39:15+00:00 2026-05-23T22:39:15+00:00

Using T-SQL, how do you find the sum of DateTime values for x amount

  • 0

Using T-SQL, how do you find the sum of DateTime values for x amount of records?

Example:

id(int) |  name(varchar) |  TimeInWomb(datetime)
---------------------------------------
 id1    |     name1      |     TiW1
 id2    |     name2      |     TiW2
 id3    |     name1      |     TiW3
 id4    |     name1      |     TiW4
  .     |       .        |      .
  .     |       .        |      .
  .     |       .        |      .

I want to find the sum of the TimeInWomb’s where name = name1.

Thanks.

EDIT:

I admit, in hindsight that was a pretty bad example which I’ve now changed. By “sum” I mean the sum of the hours/days/weeks/months of all the values where name = name1.

ANSWER:

You can’t sum datetimes.

  • 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-23T22:39:15+00:00Added an answer on May 23, 2026 at 10:39 pm

    I noticed in your edit that you changed your “date of birth” column to “time in womb”. Those are two very different concepts. “date of birth” is a SINGLE point in time, where “time in womb” is a DURATION of time. Which of these two concepts are you trying to represent?

    • If you’re trying to represent a single point in time, then doing a “sum” doesn’t make any sense. You can’t have a sum of two points in time.
    • If you’re trying to represent a duration of time, then you shouldn’t be using a DATETIME column. DATETIME is used to refer to a single point in time. You should either have two DATETIME columns (a start and an end), or you should have number column (number of seconds, or something similar).

    Either way something is conceptually wrong here and we can’t give you an answer until you get things sorted out. Some sample data with expected output would help dramatically.

    Edit:

    Since you’re trying to represent a duration of time (the time in the womb), then you need to either have two DATETIME columns (time of conception and time of birth, for example) or a single number column (seconds in womb, for example). The second option is easier to work with, but the first option gives you more flexibility.

    Let’s assume that you’ve got a SecondsInWomb column that is a number. The answer to your original question would be:

    SELECT SUM(SecondsInWomb) FROM table WHERE name = 'name1'
    

    That will tell you the total amount of seconds spent in the womb for that name.

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

Sidebar

Related Questions

I'm trying to find SQL statements that timed out using the SQL 2005 profiler.
Although using SQL FOR XML EXPLICIT is cumbersome, I find myself using it often.
I am using SQL Server 2005, I want to find out what all the
I am using MS SQL Server 2005 (9.0.4035) and trying to find rows that
I've been using Linq to SQL for some time now and I find it
I am trying to write T-sql script which will find open records for one
I'm using SQL Server 2008. I have a table with over 3 million records,
How can i find the fifth record in a table using sql query?
I'm using SQL Server 2008. I'm trying to find out which connection within to
I'm trying to find the default location for all my local databases using sql

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.