Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Formatting a date/time with PowerShell

Posted on 2016-08-01
4
Medium Priority
?
30 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 2000 total points
ID: 41737872
([WMI]'').ConvertToDateTime('20160801164123.157000+000').ToString('yyyyMMdd HH:mm:ss')

Open in new window

1
 
LVL 46

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
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.
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 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