subtracting 2 datetime values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tomcbr
    New Member
    • Oct 2011
    • 2

    subtracting 2 datetime values

    I need to subtract 2 datetime values.

    The values are from the same view table but 2 different rows.

    The points in the table are Alarm points which are generated via an after hours push button for air conditioning. The first point is the time the alarm is first initiated and the second is the time the alarm is disabled after the after hours timer disables.

    Below are the queries which I am using to retrieves each value presently.

    Code:
    SELECT LastAlarmDetailsByTime.originalAlarmTime
    FROM         LastAlarmDetailsByTime
    WHERE      (lan = 20) AND (os = 41) AND (theModule = N'i1') AND (AlarmCode = N'DI=1')
    ORDER BY originalAlarmTime DESC
    Code:
    SELECT LastAlarmDetailsByTime.originalAlarmTime
    FROM         LastAlarmDetailsByTime
    WHERE      (lan = 20) AND (os = 41) AND (theModule = N'i1') AND (AlarmCode = N'CDI1')
    ORDER BY originalAlarmTime DESC
    Last edited by NeoPa; Oct 6 '11, 10:15 PM. Reason: Added mandatory [CODE] tags for you
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What is the column that link this two? Equipment ID perhaps? And your query is almost identical, too. Do you just need the value from the previous row after sorting by date?


    ~~ CK

    Comment

    • tomcbr
      New Member
      • Oct 2011
      • 2

      #3
      I am a little unsure what you mean by “column that links the two”
      Basically I need to subtract the first query’s "originalAlarmT ime" from the second query’s "originalAlarmT ime".

      Sorry for my ignorance, I am very new to this as I am an electrician working with building management systems.

      Comment

      Working...