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

  • Home
  • SEARCH
  • 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 6537189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:35:14+00:00 2026-05-25T10:35:14+00:00

I have these fields in my T-SQL database – startTime and endTime and processTime

  • 0

I have these fields in my T-SQL database – startTime and endTime and processTime.
The process time is the amount of time from start to end time.
So, one startTime example is 22:50:59 and its endTime is 23:14:23.
Process time would be .39 (The current code):

SELECT convert( decimal(18,0), totalItems 
        /(datediff(ss,sessionStartTime,sessionEndTime)/60.00/60.00) ) 
  AS processTime

This seems to be working for the most part, but it doesn’t work when the startTime and endTime span across a day – for example, a startTime is 23:17:27 and an endTime of 00:31:23.

In other words, they started at 10:17 p.m., and finished at about 12:31 a.m. the following morning, but SQL isn’t seeing this, because the processTime is displaying as a negative number (-22.77)…
How do I convert these negative times into positive times?

I do have separate date fields – a startDate, and an endDate.

  • 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-25T10:35:14+00:00Added an answer on May 25, 2026 at 10:35 am

    I’m assuming you’re including dates…(?)

    Here is a sample I ran — seems to work as expected:

    declare @start datetime
    declare @end datetime
    
    set @start = '2011-09-06 23:17:27'
    set @end = '2011-09-07 00:31:23'
    
    select 
        datediff(second,@start,@end) as seconds, 
        datediff(minute,@start,@end) as minutes,
        datediff(hour,@start,@end) as hours,
        datediff(day,@start,@end) as days,
        datediff(month,@start,@end) as months,
        datediff(year,@start,@end) as years
    

    Here’s the results:

    seconds     minutes     hours       days        months      years
    ----------- ----------- ----------- ----------- ----------- -----------
    4436        74          1           1           0           0
    
    (1 row(s) affected)
    

    One thing you might do is re-check the scope of your decimal conversion. E.g.: this produces a different results, depending on where you put the parens before the division:

    declare @start datetime
    declare @end datetime
    
    set @start = '2011-09-06 23:17:27'
    set @end = '2011-09-07 00:31:23'
    
    select convert(decimal(18,0), (datediff(ss,@start,@end)))/60.00/60.00 as NEW_processTime,
           convert(decimal(18,0), (datediff(ss,@start,@end)/60.00/60.00)) as ORIGINAL_processTime
    

    Here are the results of that:

    NEW_processTime                         ORIGINAL_processTime
    --------------------------------------- ---------------------------------------
    1.23222221666                           1
    
    (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 an SQL Server DB with a table with these fields: A bit
I have a database table (named Topics) which includes these fields : topicId name
I've imported a country database from somewhere, with these fields: Abbr varchar(2), FullName varchar(50)
Let's say I have DatabaseA with TableA, which has these fields: Id, Name. In
In a legacy database (SQL Server 2000), we have a clustered index that looks
I have an SQL Server 2005 database, and I tried putting indexes on the
We are upgrading/converting several old Access databases to MS-SQL. Many of these databases have
We have a web application that is built on top of a SQL database.
I have a very large database I need to diagram. The database is SQL
I've recently added a couple of fields to some tables in my database (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.