Store Current Datetime according to client side timezone in sqlServer

前端 未结 1 1746
灰色年华
灰色年华 2021-01-16 17:40

I have dateTimeAuth column in sql table of datatype datetime and its default value is (getdate()) which returns me current time if i run my project at offline mode. When i u

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-16 18:08

    getdate() will always return the date and time where the server is located. If you want the date and time from your user's timezone, you need to send the date from the application and insert it as a regular dateTime variable

    but if you are on SQL 2008, you can use

    SELECT SYSDATETIMEOFFSET()
    

    to get the date on your timezone. You can also add dates to it (+5:30 from UTC = IST)

    SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30')
    

    0 讨论(0)
提交回复
热议问题