Get the smallest timespan between two entries

From: mike (mike_at_discussions.microsoft.com)
Date: 10/27/04


Date: Wed, 27 Oct 2004 03:49:07 -0700

Hi all,

we have a table with a column of type "datetime"

We want to get the smallest timespan between two entries.

Now we get this timespan with the following query (it works but it's to
slow, it runs 5 secs with 250000 entries):

select min(Datediff(minute,a.rectime,b.rectime))
from dbo.value a, dbo.value b
where b.rectime = ( select min(rectime) from dbo.value
                     where rectime > a.rectime )

Any idea? Thanks in advance,

Mike



Relevant Pages

  • Re: Sorting and non-unique keys
    ... strings, DateTime and Timespan). ... while at other times in TimeSpan order. ... The resulting compound key can be used as the key portion of any IDictionary as long as uniqueness of the overall compound key is maintained. ... In the above example both members happen to be long ints, but the types of the members can be mixed in any way as long as each member is a type which is IComparable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Timespan and time formatting
    ... I'm forced to use a Timespan object. ... (DateTime also has a SubTract method). ... As a workaround I convert the TimeSpan to a DateTime & format the DateTime. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: When 10 minutes before midnight is out of range.
    ... >> used routines in programming. ... > first is expressed by a Date (DateTime) value and the second by a Timespan ... > and all the other members. ...
    (microsoft.public.dotnet.general)
  • Making Dates with .NET
    ... of the DateTime value type before you can use it. ... out of the string that's passed to it. ... to it must exactly match the format that you specify in the ... returned value is expressed in a TimeSpan: ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Making Dates with .NET
    ... of the DateTime value type before you can use it. ... out of the string that's passed to it. ... to it must exactly match the format that you specify in the ... returned value is expressed in a TimeSpan: ...
    (microsoft.public.dotnet.framework.windowsforms)