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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:38:10+00:00 2026-06-12T05:38:10+00:00

I have a simple data set shown in Table 1 below. I would like

  • 0

I have a simple data set shown in Table 1 below. I would like to produce two new columns (START_SHIFT_DT_TIME and END_SHIFT_DT_TIME) using the columns from Table 1. The desired output is shown in Table 2.

The requirements are:

  1. If the START_SHIFT hours starts on or after 22:00:00 then the actual start date is the previous day.
  2. If the START_SHIFT hours starts before 22:00:00 then the actual start date is the following day.

I am using SQL server.

Table 1:

START_SHIFT END_SHIFT       DATE    
22:00:00    06:00:00        1/13/2012 12:00:00 AM
07:00:00    15:00:00        1/13/2012 12:00:00 AM
23:30:00    07:30:00        2/27/2012 12:00:00 AM
00:00:00    08:00:00        2/17/2012 12:00:00 AM
17:00:00    01:00:00        1/1/2012 12:00:00 AM

Table 2:

START_SHIFT END_SHIFT     DATE                  START_SHIFT_DT_TIME     END_SHIFT_DT_TIME
22:00:00    06:00:00      1/13/2012 12:00:00 AM  1/12/2012 10:00:00 PM  1/13/2012 6:00:00 AM
07:00:00    15:00:00      1/13/2012 12:00:00 AM  1/13/2012 7:00:00 AM   1/13/2012 3:00:00 PM
23:30:00    07:30:00      2/27/2012 12:00:00 AM  2/26/2012 11:30:00 PM  2/27/2012 7:30:00 AM
00:00:00    08:00:00      2/17/2012 12:00:00 AM  2/17/2012 12:00:00 AM  2/17/2012 8:00:00 AM
17:00:00    01:00:00      1/1/2012 12:00:00 AM   1/1/2012 5:00:00 PM    1/2/2012 1:00:00 AM
  • 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-12T05:38:11+00:00Added an answer on June 12, 2026 at 5:38 am
    SELECT
      START_SHIFT,
      END_SHIFT,
      DATE,
      DATEADD(SS,
              DATEDIFF(SS,0,START_SHIFT),
              DATEADD(D,
                      CASE WHEN START_SHIFT >= '22:00' THEN -1 ELSE 0 END,
                      DATE)) START_SHIFT_DT_TIME,
      DATEADD(SS,
              DATEDIFF(SS,0,END_SHIFT),
              DATE) END_SHIFT_DT_TIME
    FROM TBL
    

    The pattern used in the last column is that the time component in END_SHIFT is converted to seconds and then added to the DATE. In the 4th column, the same pattern is used and it goes through an additional step of adding -1 day (previous) when START_SHIFT is 22:00 or later.

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

Sidebar

Related Questions

I have fit a simple bi-variate VAR model to this data set and I
I have a simple data model of two tables, email and recipients, email can
I'm new to WCF data services. I have a quite simple data model. Some
I have data in a table that looks like the following sample data: varchar(20)
I have a simple form that inserts data in a table on my server.
I have a sample table (table_name: track_task) like below: task_id stage log_date ---------------------------------------- 3
I have only simple data types in method signature of service (such as int,
Let's say I have some simple data y = [[datetime.datetime( 2012,1,1,1,1), 2.1], [datetime.datetime( 2012,1,1,1,2),
I have a simple WCF Data Services service and I want to expose a
I have simple SSIS package which reads data from flat file and insert into

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.