Problem with insert getdate() --> always add one hour

  • Hi Gurus,

    i have this sql:

    insert into [MDE Pickup Msg]([Document ID], [Application], WEB_Date_Created, VIN,TRPNR ,[Line No_]) values ('AU08-008798' , 1 , getdate(), 'VF1VY0B0NUC257686', 'TA08-01955', 50000 )

    i can execute it - but the Colum WEB_Date_Created which is filled with getdate() has the current time + 1 hour in the table.

    When i only try select getdate() i get the right time.

    Does anybody have a glue?

    Greetings form Austria 🙂

  • Are there any triggers on the table?

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • 1) Look at the column is it a computed column.

    2) Take a look at the system time on the DB Server.

    3) Make sure you use always a GetUTCDate() rather than a getdate() because of issues with CC Regions and other bit of stuff.

    Put the profiler on and check whats being passed down to the db.

    is your component doing some thing special to add an hour to it or so.

    Regards
    Vinay

  • Thanks for all answers!

    No - there are no triggers in this table.

    With GetUTCDate() in the insert statement i could store the right time.

    Thank you 😉

  • I’m sorry but something here seems strange. In your first post you wrote about a table that when you run an insert statement into it and you use getdate(), you get the wrong date in the table. If I understood your post correctly if you’ll run the script bellow, the select statement will return 2 different dates:

    insert into [MDE Pickup Msg]([Document ID], [Application], WEB_Date_Created, VIN,TRPNR ,[Line No_])

    values ('TEST-999999' , 1 , getdate(), 'VF1VY0B0NUC257686', 'TA08-01955', 50000 )

    select WEB_Date_Created, getdate() from [MDE Pickup Msg]

    go

    --clean the extra record that was inserted only as a test

    delete [MDE Pickup Msg] where [Document ID] = 'TEST-999999'

    The function getdate() gets it’s value from the OS. The function getutcdate() also gets the local time from the OS just as the function getdate() does. This means that both functions get the same time and date. The difference is that getutcdate() function also checks the time zone settings of your server and according to your time zone, it knows the difference between your local time and UTC time. Then it has all the needed information to know the UTC time. Since both functions getdate() and getutcdate() get the local time from the same source, I find it hard to believe that one is getting the correct time and the other one is getting the wrong time. If you are inserting the UTC time as is and your time zone has 1 hour difference from UTC time, then the problem still exists. I would still try to find out why the time that I insert is getting modified.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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