Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Find Difference between Start and End timestamps

Posted on 2010-11-09
3
774 Views
Last Modified: 2012-05-10
Hi I have a table which has start and end time timestamp columns. The table has entries for files and the start and end times for them. These are basically the load times for that file into a table.
I want to find the time between the loading of 2 files.

Let me explain

eg
 Col1   StartTime                                     Endtime
     1    2010-11-09 20:12:22.503          2010-11-09 20:12:22.800
     2    2010-11-09 20:12:27.923      2010-11-09 20:12:28.203
     3     2010-11-09 20:12:33.350      2010-11-09 20:12:33.617
     4     2010-11-09 20:12:38.580           2010-11-09 20:12:38.863
     5    2010-11-09 20:12:43.890      2010-11-09 20:12:44.170


I want to write a query that will give me time difference between

start time of 2 and endtime of 1
start time of 3 and endtime of 2
start time of 4 and endtime of 3  
and so on

the difference will be very small..

So the time between completion of 1st file and start of loading of 2nd file is in this case
   2010-11-09 20:12:27.923  
 - 2010-11-09 20:12:22.800

= 00:00:00.123 sec   (923-800    only the milisec part in this case )

Similarly I want to find time between loading for all the files



I have a column "duration" that gives me difference between the start and endtime of the same row.
Now I want to find out the time lapse between the end of row1 and start of row2 and so on for all the rows.


All the help is greatly appreciated

Thanks

0
Comment
Question by:esotericmee
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 250 total points
ID: 34099484
Let's say the table is called 'Times'
Unfortunately there is no 'next_record' operator, but you could do something like this.

SELECT datediff(ms, A.EndTime, B.StartTime) AS TimeDiff
FROM Times A INNER JOIN Times B ON A.Col1 + 1 = B.Col1
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34099491
If Col1 isn't reliable then do it like
SELECT datediff(ms, A.EndTime, (SELECT min(StartTime) FROM Times B WHERE B.StartTime > A.StartTime) AS TimeDiff
FROM Times A
0
 

Author Comment

by:esotericmee
ID: 34128527
That helped..Thanks a lot...I appreciate it
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question