Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2007
    Posts
    5

    Unanswered: Query for Difference between two Fields

    Can anyone please help me to find the diffence between two fields.

    Field1 - 16:12:27:123
    Field2 - 16:12:36:750


    I need to find the difference between field2 and field1??

  2. #2
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716
    Looks to me like the difference is 9:627 !


    When you say you need to find the difference, are you talking about determining that they ARE different, or finding the elapsed time?

    If it's the latter, take a look into DATEDIFF in BOL...

    Also, it would help if you tell us what type of field you have there...as that would also effect the answer.
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

  3. #3
    Join Date
    Sep 2007
    Posts
    5

    Query for Difference between two Fields

    I need to find the the difference between two times.

    Data Types - Field1 and Field2 are both nvarchar

  4. #4
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716
    Look up DATEDIFF in BOL for starters...

    DATEDIFF(ms, Field1, Field2)
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    DECLARE @foo		NVARCHAR(50)
    ,  @bar			NVARCHAR(50)
    
    SET @foo = N'16:12:27:123'
    SET @bar = N'16:12:36:750'
    
    IF 0 = IsDate(@foo)
       PRINT 'foo is not a date'
    IF 0 = Isdate(@bar)
       PRINT 'bar is not a date'
    ELSE
       SELECT DateDiff(ms, @foo, @bar)
    -PatP

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •