locked
diff between Two columns RRS feed

  • Question

  • In sqlserver -2005 i am  created three columns

               Column name    datatype

    one is  BeginTime        datetime

    second EndTime         datetime

    third     TotalTime   in properties computed column specification   Formula ([EndTime]-[BeginTime])

     

    10/12/2009 12:00:00 AM

    12/12/2009 12:00:00 AM

    result come like -- 3/3/1900 12:00:00 AM but this is wrong .

     

    Please any one help.


    nadeer
    Wednesday, March 25, 2009 1:43 PM

Answers

  •  Use SQL DATEDIFF() Function, but you need to store the difference between two date time columns as integer.
    • Marked as answer by Raymond-Lee Monday, April 6, 2009 5:28 AM
    Wednesday, March 25, 2009 1:51 PM
  • Use DATEDIFF function with whatever the datepart you want,

    ex:

    SELECT DATEDIFF(year, '2005-12-31 23:59:59.9999999'

    , '2006-01-01 00:00:00.0000000');


    or

    SELECT DATEDIFF(minute, '2005-12-31 23:59:59.9999999'

    , '2006-01-01 00:00:00.0000000');

    • Marked as answer by Raymond-Lee Monday, April 6, 2009 5:28 AM
    Wednesday, March 25, 2009 1:52 PM

All replies

  •  Use SQL DATEDIFF() Function, but you need to store the difference between two date time columns as integer.
    • Marked as answer by Raymond-Lee Monday, April 6, 2009 5:28 AM
    Wednesday, March 25, 2009 1:51 PM
  • Use DATEDIFF function with whatever the datepart you want,

    ex:

    SELECT DATEDIFF(year, '2005-12-31 23:59:59.9999999'

    , '2006-01-01 00:00:00.0000000');


    or

    SELECT DATEDIFF(minute, '2005-12-31 23:59:59.9999999'

    , '2006-01-01 00:00:00.0000000');

    • Marked as answer by Raymond-Lee Monday, April 6, 2009 5:28 AM
    Wednesday, March 25, 2009 1:52 PM