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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:00:27+00:00 2026-06-11T11:00:27+00:00

Below is my table structure in ms access, SNo Time EmpId Date Type ——————————————-

  • 0

Below is my table structure in ms access,

SNo    Time        EmpId    Date      Type
-------------------------------------------
  1   09:20:53 AM    1     9/12/2012  IN      
  2   09:50:12 AM    1     9/12/2012  OUT 
  3   09:52:09 AM    1     9/12/2012  IN
  4   12:15:10 PM    1     9/12/2012  OUT

The output should compare time and find the difference in 1st two rows and the next 2 (3rd and 4th) rows
Output required is,

EmpId   Date          Time
 1     9/12/2012     0:30:41
 1     9/12/2012     2:23:01

Could Somebody kindly help please.Would really appreciate 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-06-11T11:00:28+00:00Added an answer on June 11, 2026 at 11:00 am

    I think this query is close to what you want, assuming your Date and Time fields are both Date/Time data type. If they are actually text type, you can transform their values with CDate(). But either way, I think a query would be easier with a single field to hold both the date and time rather than separate fields for each.

    SELECT
        sub.SNo,
        sub.EmpId,
        sub.Type,
        sub.start_time,
        sub.end_time,
        Format(sub.end_time - sub.start_time, 'h:nn:ss') AS duration
    FROM
        (
            SELECT
                o.SNo,
                o.Date + o.Time AS end_time,
                o.EmpId,
                o.Type,
                (
                    SELECT TOP 1 i.Date + i.Time
                    FROM YourTable AS i
                    WHERE
                            i.Type = 'IN'
                        AND i.EmpId = o.EmpId
                        AND i.Date + i.Time < o.Date + o.Time
                    ORDER BY i.Date, i.Time DESC
                ) AS start_time
            FROM YourTable AS o
            WHERE o.Type='OUT'
        ) AS sub;
    

    BTW, Date, Time and Type are reserved words and therefore not ideal choices as field names. Although those names weren’t a deal-breaker for this query, you could avoid other potential headaches by renaming those fields if possible.

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

Sidebar

Related Questions

My table structure is below: CREATE TABLE [ACC].[Document]( [DocumentID] [int] IDENTITY(1,1) NOT NULL, [Date]
I have a mysql database with a table structure like below : Table Name
My table structure is below : MyTable (ID Int, AccID1 Int, AccID2 Int, AccID3
I have a table structure having a EMP_DATE column as below ID EMP_DATE ----
I have a table with below structure. I am not having control over changing
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have two table masterTbl and detailTbl which structure is given below... --PRIMARY TABLE
I have a table structure like below : categoryID bigint , primary key ,
I have below table structure in MS SQL AirQuoteID Name SalesValue 7 M 49.50
Is it possible to get the result as below from the same table date-wise

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.