我想将datetime2字段从Azure SQL表转换为给定时区(在这种情况下' Mountain Standard Time')
SELECT [Created] AT TIME ZONE 'Mountain Standard Time' FROM MyTable
返回格式" 03/26/2018 17:00:11 -06:00"的结果,这是一个datetimeoffset,不能直接CAST或CONVERTED到datetime或datetime2
以下给出了我需要的答案,但肯定必须有一个不那么详细的方法
SELECT DATEADD(minute, DATEDIFF(minute, CONVERT(datetimeoffset,[Created] AT TIME ZONE 'Mountain Standard Time'), [Created]), [Created]) AS CreatedLocalTime FROM MyTable