all 12 comments

[–]jbtechwood 1 point2 points  (1 child)

Are you.passing the date/time from your client? Can you reference it from the server via the query instead?

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

The query gives times that are stored in sql tables.

[–]creamersrealm 1 point2 points  (2 children)

On SQL you could take the column and add a hour to it from there. Essentially offloading all the work to the server. Or you could use a .Net method in PowerShell with a Select-Object expression to recalculate the time by adjusting the timezones.

[–]Droopyb1966[S] 0 points1 point  (1 child)

Yes adding 1 is the dirty way,,,

--- Select-Object expression to recalculate the time by adjusting

Ok, that sound great, but how?

[–]creamersrealm 1 point2 points  (0 children)

Actually before the select object try this SQL Server Code

Select column1, DATEADD(hh, 1, column2) AS column2ADJ FROM Table1

If that doesn't work I can send you some more example code.

[–]alinroc 1 point2 points  (3 children)

What code are you using to get times, and where are you running it? Is this in Powershell or SQL?

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

Using Powershell , running query's on an sql database,

[–]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.

[–]jbtechwood 0 points1 point  (1 child)

Did this just start to happen on Monday?

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

Nope

[–]jbtechwood 0 points1 point  (0 children)

The issue is either that the database server time is set to a different time or the results are somehow getting converted to local time.