none
how to use dateadd/datediff function in MSSQL to determine a Previous point in time RRS feed

  • Question

  • I have a requirement where i have a start date say '11/23/2008 11:34:00 AM'
    and I want to know what date was 3 hours before the above stated time
    ( '11/23/2008 08:34:00  AM')


    I wrote a function which converted the given datetime to second and then subtracted the timeLag (3hr) to second and again converting the result back to DATETIME. can someone suggest a cleaner solution
    Tuesday, May 26, 2009 8:26 AM

Answers

  • Got the solution ::

    DATEADD ( hour, -3, @datetime)

    where @datetime is the point in time from where you desire the next result

    • Marked as answer by Parag Agrawal Wednesday, May 27, 2009 8:51 AM
    Tuesday, May 26, 2009 9:31 AM