#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Get Local Time From UTC

Be sure to check out my Scripting4Crypto initiative. It’s a fun way to get into using cryptocurrencies all while getting your PowerShell needs met.

I recently had a request for advice on how to deal with date time data being returned when running the Get-PWUserAuditTrailRecords cmdlet.  The date time values are being returned in UTC (Coordinated Universal Time) and the user needed it in local time.

We will be using the following cmdlets to accomplish this task. All of the ProjectWise related cmdlets are available using the PWPS_DAB module. At the time of this post, I am using version Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.

  • Get-PWUserAuditTrailRecords
  • Get-PWUsersByMatch
  • Out-GridView

First thing we need to do is get the audit trail records desired. To do this we will run the Get-PWUserAuditTrailRecords cmdlet specifying the user account and date range desired. The object returned will be a datatable containing all of the appropriate audit trail records.

# Get audit trail records for user, for the dates specified.
$Splat_AuditTrail = @{
Users = (Get-PWUsersByMatch -UserName 'brian.flaherty')
StartDate = '2020-04-01'
EndDate = '2020-04-03'
$dtAuditTrailRecords = Get-PWUserAuditTrailRecords @Splat_AuditTrail

I will use the Out-GridView to show some of the output. You can also use the .GetType() to verify the data type of the $dtAuditTrailRecords variable.

$dtAuditTrailRecords | Out-GridView 



The ActionDate values are returned as UTC time. We will add a new column to the datatable to store the ActionDate as the local time, which in this instance is CST (Central Standard Time). 

NOTE: There is a 5 hour difference between UTC and CST.

# Add new column to store the local time.

Now that the new column has been added, we can loop through each row in the datatable, convert the ActionDate to the local time and add the converted value to the new column.

foreach ($row in $dtAuditTrailRecords.Rows) {
$row.ActionDateLocal = ($row.ActionDate).ToLocalTime()

The following shows the contents of the datatable after adding and updating the ActionDateLocal column.


Experiment with it and have fun.

Hopefully, you find this useful. Please let me know if you have any questions or comments.  If you like this post, please click the Like button at the bottom of the page.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.