Solved

Formatting a date/time with PowerShell

Posted on 2016-08-01
4
26 Views
Last Modified: 2016-08-01
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
0
Comment
Question by:Lorrec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 41737872
([WMI]'').ConvertToDateTime('20160801164123.157000+000').ToString('yyyyMMdd HH:mm:ss')

Open in new window

1
 
LVL 45

Expert Comment

by:aikimark
ID: 41737920
@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

0
 

Author Comment

by:Lorrec
ID: 41737929
Thank you for the assistance. This was helpful.
0
 

Author Comment

by:Lorrec
ID: 41737933
Thank you aikimark for the assistance as well.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question