Store Current Datetime according to client side ti

2019-02-20 17:06发布

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 uploaded it to live server it stores current time of default timezone GMT. I want value to be stored according to IST. How can it be done ?

Value stored accoding to GMT : 8/26/2010 1:02:28 PM Actual time accodring to IST :8/26/2010 7:02:28 PM

1条回答
地球回转人心会变
2楼-- · 2019-02-20 17:23

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')
查看更多
登录 后发表回答