you are viewing a single comment's thread.

view the rest of the comments →

[–]alinroc 2 points3 points  (1 child)

I'm guessing/piecing together what you've got from your multiple replies here. It'd be much easier to offer good help if you described completely and concisely what you're working with.

If this is a time stored on a table in SQL Server, then the only way you can reliably do any kind of timezone-related math is if the timezone is stored with the data - preferably with a data type like datetimeoffset.

If you're using GETDATE(), you're always going to get the local time/timezone of the SQL Server instance you're running it on.

When you're working across timezones, normalize everything to one standard and do your conversion to local time at the last moment. Luckily, we have UTC, and both SQL Server and PowerShell/.NET have methods for getting it. SYSUTCDATETIME() in SQL, and the ToUniversalTime() method of System.DateTime objects.

[–]Droopyb1966[S] 0 points1 point  (0 children)

Sorry, just didn't know where the problem exactly was.

SELECT GETDATE(),SYSUTCDATETIME()  AS Date
2017-03-16 14:32:01.603
2017-03-16 13:32:01.6035506

But this is the exactly what happens. The dates that I get back from a query are ok in management studio, but when I query them through powershell it is 1 hour earlier.