Deduct 60 minutes from getdate() ?

  • A quick question .

    How do I deduct 60 minutes fro a date?

    for eg: if my getdate() returns  2005-10-11 10:37:35.153 then I need the out put as

    2005-10-11 09:37:35.153

  • Either

    SELECT DATEADD(mi,-60,GETDATE())

    or

    SELECT DATEADD(hh,-1,GETDATE())

    First subtracts 60 minutes, second subtracts 1 hour.

    HTH

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thank you very much.

    Can we use datediff?

    Rajesh

     

  • Not for what you're trying to do.

    From Books Online:

    The DATEADD function adds an interval to a date you specify.

    The DATEDIFF function calculates the amount of time in dateparts between the second and first of two dates you specify. In other words, it finds an interval between two dates.

    ie. use DATEADD to add a certain number of intervals (eg. hours, days, years) to a date, use DATEDIFF to calculate the number of intervals (eg. hours, days, years) between two dates.

    Run the following for an example

    SELECT DATEDIFF(dd,'2005/10/01','2005/10/30') AS DateDifference, DATEADD(dd,25,'2005/10/01') DateAdded

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply