sql - TSQL update date with today from datetimeoffset column -
sql - TSQL update date with today from datetimeoffset column -
i have table 3 columns: id (int, pk) time (datetimeoffset) storedvalue (int)
i need update date in time column today, each row according timezone stored in datetimeoffset (but dont alter time or timezone info). illustration if stored value is: 2014-10-08 08:25:46.0000000 +04:00 , today timezone is: 2014-10-20, should become:2014-10-20 08:25:46.0000000 +04:00 if today still 2014-10-19 timezone, should set to: 2014-10-19 08:25:46.0000000 +04:00.
how can in tsql?
update: perchance messy , incomplete reply not update correctly each row according timezone, based on answers below:
declare @date datetimeoffset = sysdatetimeoffset() declare @date2 datetimeoffset(4) = '12-10-25 12:32:10.1237 +01:0' convert(datetimeoffset, datetimeoffsetfromparts(datepart(yyyy, @date), datepart(mm, @date), datepart(dd, @date), datepart(hh, @date2), datepart(mi, @date2), datepart(ss, @date2), datepart( millisecond, @date2), cast((floor(datepart(tz, @date2)) / 60) varchar(10)), cast((datepart(tz,@date2)%60) varchar(10)), 3))
declare @date datetimeoffset = '2013-01-31 10:02:12 +02:00' select @date,convert(datetimeoffset, dateadd(day, 18, @date))
please check above code.
sql sql-server tsql datetimeoffset
Comments
Post a Comment