Getdate() function to get date for my timezone

后端 未结 5 1069
执念已碎
执念已碎 2021-01-05 05:49

I would love to insert a default value into a column with data type datetime2(7). However, because my website is hosted on a server in a different timezone, the getdate func

5条回答
  •  独厮守ぢ
    2021-01-05 06:16

    You can use SYSDATETIMEOFFSET function

    select SYSDATETIMEOFFSET()
    

    MSDN description:

    Returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.

    More on MSDN.


    Based on clarification in the comment below:

    Because you want to store the local time of the client, SQL Server has no way of knowing what is your local time. The best option that would work best would be to send the current time from the client each time.

提交回复
热议问题