Add 2 hours to a time value!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jullianps
    New Member
    • Feb 2008
    • 7

    Add 2 hours to a time value!

    Hi Guys and lets start by saying that this is my first post, I would like to thank in advance to those who can give me a hand and lets start with the quesiton...

    The problem probably could sound super easy for some of you but I cant figure out how to do it yet, I have a Datetime field on a MS SQL server DB and it gets its default value through Getdate() and it works fine but the problem is that I need to add 2 hours to the ending time (which is part of the value since it contains the date too) for example:


    2/27/2008 8:21:13 AM <--------------This is in my DB now

    2/27/2008 10:21:13 AM <--------------This is what I would like to have

    Probably it can be done at the very moment of insertion or probably it needs to be done after the value has been inserted through an update in some sort.


    Again thanks for the help provided
    Marco
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    You're looking for DATEADD function. Just use hour as your datepart.

    -- CK

    Comment

    • jullianps
      New Member
      • Feb 2008
      • 7

      #3
      Thanks so much Ive opened the link and it looks like what I need !
      Marco

      Comment

      • jullianps
        New Member
        • Feb 2008
        • 7

        #4
        Awesome, Worked like a charm I ended up adding a trigger for Insert and this was the simple Update statement that made it work


        CREATE TRIGGER [Add2hours] ON [DB].[dbo].[Table]
        FOR INSERT
        AS
        Update fileslog set date_time=DATEA DD(hh, 2, date_time)


        Thanks for the tip
        Marco

        Comment

        Working...