Good day!

Tell me, maybe someone came across ... Is there a T-SQL (MSSQL) function for converting the already recorded DateTime values ​​in the table to universal time (where there is no correction for the translation of hours).

CONVERT(CHAR(), DateTimeField, 127) and CONVERT(CHAR(), DateTimeField, 126) for some reason give the same value, although it is written everywhere that the first should output Z - hour shift.

The DATEDIFF(s, GETDATE(), GETUTCDATE()) not appropriate, as it only gives a shift for the current moment, which may differ from six months ago ...

Perhaps there are some locale based solutions? Or can I set a time zone for a transaction / connection?

THANK!

    1 answer 1

    The datetime field does not store a UTC offset, so the shift “six months ago” cannot be obtained from it. If you need to store data at different offsets, use datetimeoffset. And read the source: http://msdn.microsoft.com/ru-ru/library/ms186724.aspx

    • Yes. In principle, I myself came to this, but I really wanted someone to confirm that I was not mistaken. Alas, the base is already ready, and what is worse - with impressive data - the new is not difficult to fix; The old had a long time and you need to level it with your hands on the points of translation of hours))) Thank you! - SilverIce