Link to home
Start Free TrialLog in
Avatar of Jeffrey Renfroe
Jeffrey RenfroeFlag for United States of America

asked on

Formatting a date/time with PowerShell

I have a date/time like the below. I have tried different methods but cannot get it formatted properly. Can someone point me in the right direction?

Current Format
20160801164123.157000+000

Desired Format

yyyyMMdd HH:mm:ss
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Lorrec

How important are the fractions of a second in your conversion?  The fractional seconds are being ignored by the posted solution as well as this alternative solution.
[System.Management.ManagementDateTimeConverter]::ToDateTime('20160801164123.157000+000').ToString('yyyyMMdd HH:mm:ss')

Open in new window


Note: I find some of these methods rather verbose.  I prefer something like this:
$DTC=[System.Management.ManagementDateTimeConverter]
$DTC::todatetime('20160801164123.957000+000').ToString('yyyyMMdd HH:mm:ss')

Open in new window

Avatar of Jeffrey Renfroe

ASKER

Thank you for the assistance. This was helpful.
Thank you aikimark for the assistance as well.