Changing UTC Time to Local Time using scalar-valued function with Select statements SQL -
i've been trying work on 2 days , still stuck. assistance or tips appreciated.
creating function date conversion:
create function localdatefromutctime ( @utcdatetime datetime ) returns datetime begin declare @diff int; set @diff = datediff(hh,getutcdate(), getdate()); return dateadd(day, datediff(day, 0, dateadd(hh, @diff, @utcdatetime)),0); end then select sql statement i'm trying use function above below:
select o.number 'order#', o.[guid] 'guid', dbo.localdatefromutctime(o.settlementdate) 'closing date' pf.order o doing displays settlement date no timestamp.
2015-07-15 00:00:00.000 how change show correct local time?
thanks
your date conversion returning difference in days. dateadd adding number of days between date 0 (which 01-01-1900) , utc date onto different date 0. means hours , minutes ignored.
if want include hours , minutes need drop dateadd(...datediff( part:
return dateadd(hh, @diff, @utcdatetime)
Comments
Post a Comment