繁花不似锦
如果您需要服务器位置以外的转换,此功能允许您传递标准偏移量并记录美国夏令时:-- =============================================-- Author: Ron Smith-- Create date: 2013-10-23-- Description: Converts UTC to DST-- based on passed Standard offset-- =============================================CREATE FUNCTION [dbo].[fn_UTC_to_DST]( @UTC datetime, @StandardOffset int)RETURNS datetimeASBEGIN declare @DST datetime, @SSM datetime, -- Second Sunday in March @FSN datetime -- First Sunday in November -- get DST Range set @SSM = datename(year,@UTC) + '0314' set @SSM = dateadd(hour,2,dateadd(day,datepart(dw,@SSM)*-1+1,@SSM)) set @FSN = datename(year,@UTC) + '1107' set @FSN = dateadd(second,-1,dateadd(hour,2,dateadd(day,datepart(dw,@FSN)*-1+1,@FSN))) -- add an hour to @StandardOffset if @UTC is in DST range if @UTC between @SSM and @FSN set @StandardOffset = @StandardOffset + 1 -- convert to DST set @DST = dateadd(hour,@StandardOffset,@UTC) -- return converted datetime return @DSTENDGO