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

The Archive Base Latest Questions

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

Example I want to calculate the worktime between 09:00:00 to 18:00:00, 09:00:00 – Normal_Intime

  • 0

Example

I want to calculate the worktime between 09:00:00 to 18:00:00,

09:00:00 - Normal_Intime
18:00:00 - Normal_Outtime

Suppose

1) Intime is 10:00:00, Outtime is 17:00:00 It should give the output as 07:00:00
2) Intime is 08:00:00. Outtime is 19:00:00 It should give the output as 09:00:00

above output should compare with Normal_Intime, Normal_Outtime .

Means Normal_Intime is 09:00:00 only and Normal_Output is 18:00:00 only, so Intime should not > 09:00:00 and Outtime < 18:00:00.

Query

select Intime, Outtime, CONVERT(char(8), CASE WHEN OutTime > Normal_Outtime THEN cast(Normal_Outtime AS datetime) ELSE cast(OutTime AS datetime) END - CASE WHEN InTime > Normal_Intime THEN cast(InTime AS datetime) ELSE cast(Normal_Intime AS datetime) END, 8) AS WorkTime from table

Output

Intime       Outtime        Worktime
15:37:48    22:08:15    02:22:12
07:33:34    07:59:13    22:59:13

the Second Row giving wrong output It should give only 00:25:39

If both in and out time is smaller than NormalInTime and both in and out time is greater than NormalOutTime. How to make a condtion for this

How to make a query for this conditon.

Need Query Help.

  • 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:46:54+00:00Added an answer on May 12, 2026 at 4:46 pm

    This should get you what you want

    DECLARE @Table TABLE(
            InTime DATETIME,
            OutTime DATETIME
    )
    
    INSERT INTO @Table (InTime,OutTime) SELECT '15:37:48', '22:08:15'
    INSERT INTO @Table (InTime,OutTime) SELECT '07:33:34', '07:59:13'
    
    DECLARE @Normal_InTime DATETIME,
            @Normal_OutTime DATETIME
    
    SELECT  @Normal_InTime = '09:00:00',
            @Normal_OutTime = '18:00:00'
    
    SELECT  *,
            --both dates are smaller than NotmalInTime
            CASE
                WHEN InTime < @Normal_InTime AND OutTime < @Normal_InTime THEN OutTime - InTime
                WHEN OutTime > @Normal_OutTime AND InTime > @Normal_OutTime THEN OutTime - InTime
                WHEN OutTime > @Normal_OutTime 
                    THEN @Normal_OutTime - InTime
                WHEN InTime < @Normal_InTime
                    THEN OutTime - @Normal_InTime
                ELSE OutTime - InTime
            END
    FROM    @Table
    

    But you need to take into account. What happens when the user books in before 24:00 and then books out the next day.

    And as i said, what happens in the event that book in and bookout is either before NormalTimeIn or after NormalTimeOut?

    you need to specify this.

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

Sidebar

Related Questions

I want to calculate time difference in seconds between to time instants. For example,
I want to calculate time difference in seconds between to time instants. For example,
I want to calculate the difference between two double values for example : lat1=12.2345673
Example: Suppose in the following example I want to match strings that do not
If i want to calculate the amount of k-dimensional contingency tables which formula should
I want to calculate the distance between points in C# with the google maps
i want to calculate the missing sprites. for example:- random generated sprites is displaying
For example i have such template and i want to calculate some values dynamically
Possible Duplicate: Format mysql datetime with php I want to calculate for example 10
In Mma, for example, I want to calculate 1.0492843824838929890231*0.2323432432432432^3 But it does not show

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.