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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:59:49+00:00 2026-05-27T00:59:49+00:00

I have a table with 3 columns StartDate, EndDate, ElapsedTimeInSec . I use an

  • 0

I have a table with 3 columns StartDate, EndDate, ElapsedTimeInSec.

I use an AFTER INSERT trigger to calculate the ElapsedTimeInSec.

I would like to do this:

  • If my start date is 2011-11-18 07:30:00 and my end date 2011-11-18 9:30:00 which give me a ElapsedtimeInSec of 7200 I would like to be able to split it this way.

  • Row 1 : 2011-11-18 07:30:00 / 2011-11-18 08:00:00 / 1800

  • Row 2 : 2011-11-18 08:00:00 / 2011-11-18 09:00:00 / 3600
  • Row 3 : 2011-11-18 09:00:00 / 2011-11-18 09:30:00 / 1800

How can I achieve this result ?

I dont think I made my explaination clear enough.

I have an actual table with data in it which as 2 field one with a StratDowntime and one with a EndDowntime and I would like to create a view of hours per hour base on a production shift of 12 hours (07:00:00 to 19:00:00) of the downtime.

So If I have a downtime from 2011-11-19 06:00:00 to 2011-11-19 08:00:00 I want in my report to see from 07:00:00 so the new rocrd should look like 2011-11-19 07:00:00 to 2011-11-19 08:00:00.

Another example if I do have downtime from 2011-11-19 10:30:00 to 2011-11-19 13:33:00 I should get in my report this
– 2011-11-19 10:30:00 to 2011-11-19 11:00:00
– 2011-11-19 11:00:00 to 2011-11-19 12:00:00
– 2011-11-19 12:00:00 to 2011-11-19 13:00:00
– 2011-11-19 13:00:00 to 2011-11-19 13:33:00

I hope this will clarify the question because none of the solution down there is actually doing this it is close but not on it.

thanks

  • 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-27T00:59:49+00:00Added an answer on May 27, 2026 at 12:59 am

    You could try something like:

    DECLARE @StartDate  DATETIME    = '11/18/2011 07:30:00',
            @EndDate    DATETIME    = '11/18/2011 09:30:00',
            @Runner     DATETIME
    
    
    IF DATEDIFF (mi, @StartDate, @EndDate) < 60
    
        BEGIN
    
            SELECT  @StartDate,
                    @EndDate,
                    DATEDIFF (s, @StartDate, @EndDate)
    
            RETURN  
    
        END     
    
    SET @Runner = CONVERT (VARCHAR (10), @StartDate, 101) + ' ' + CAST (DATEPART(hh, @StartDate) + 1 AS VARCHAR) + ':00:00'
    
    WHILE   @Runner <= @EndDate
    
        BEGIN
    
            SELECT  @StartDate,
                    @Runner,
                    DATEDIFF (s, @StartDate, @Runner)
    
            SET @StartDate  = @Runner
            SET @Runner     = DATEADD(hh, 1, @Runner)
    
        END
    
    SET @Runner = CONVERT (VARCHAR (10), @EndDate, 101) + ' ' + CAST (DATEPART(hh, @EndDate) AS VARCHAR) + ':00:00'
    
    SELECT  @Runner,
            @EndDate,
            DATEDIFF (s, @Runner, @EndDate)     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a event table that has the following columns: StartDate datetime EndDate datetime
I have two tables both of which have columns StartDate and EndDate. I'm trying
I need to do something like this in sql: declare @StartDate varchar(10) declare @EndDate
I have a table with rows like below id, name , phName , startDate,
I have the facts table with two date columns: StartDate and FinishDate: And I
I have a table called tblRentalRates with the following columns: rate_id (int) rate_startdate (datetime)
The table columns have the data type BLOB and CLOB. What are the corresponding
I have table with 3 columns A B C. I want to select *
I have a table with columns ID, DateStamp and the ID need not be
I have a table with columns Index, Date where an Index may have multiple

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.