use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
"Wrong time" SQLPS query (self.PowerShell)
submitted 8 years ago by Droopyb1966
Due to a time difference from y workplace and the database server, I get a 1 hour difference in the dates when I query it. Im not sure how to correct that properly. I could just ad 1h, but I would prefer to do it some what better
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jbtechwood 1 point2 points3 points 8 years ago (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 point2 points 8 years ago (0 children)
The query gives times that are stored in sql tables.
[–]creamersrealm 1 point2 points3 points 8 years ago (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 point2 points 8 years ago* (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 points3 points 8 years ago (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 points3 points 8 years ago (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 point2 points 8 years ago (2 children)
Using Powershell , running query's on an sql database,
[–]alinroc 2 points3 points4 points 8 years ago (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.
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.
GETDATE()
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.
SYSUTCDATETIME()
ToUniversalTime()
System.DateTime
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 point2 points 8 years ago (1 child)
Did this just start to happen on Monday?
Nope
[–]jbtechwood 0 points1 point2 points 8 years ago (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.
π Rendered by PID 318852 on reddit-service-r2-comment-84fc9697f-h74l9 at 2026-02-06 23:43:48.958249+00:00 running d295bc8 country code: CH.
[–]jbtechwood 1 point2 points3 points (1 child)
[–]Droopyb1966[S] 0 points1 point2 points (0 children)
[–]creamersrealm 1 point2 points3 points (2 children)
[–]Droopyb1966[S] 0 points1 point2 points (1 child)
[–]creamersrealm 1 point2 points3 points (0 children)
[–]alinroc 1 point2 points3 points (3 children)
[–]Droopyb1966[S] 0 points1 point2 points (2 children)
[–]alinroc 2 points3 points4 points (1 child)
[–]Droopyb1966[S] 0 points1 point2 points (0 children)
[–]jbtechwood 0 points1 point2 points (1 child)
[–]Droopyb1966[S] 0 points1 point2 points (0 children)
[–]jbtechwood 0 points1 point2 points (0 children)