0

I have the .csv file using 'MM DD YYYY HH:MM:SS' time format

Can I use the powershell convert to 'MMM DD, YYYY HH:MM:SS TT' ?

data.csv
09 17 2014 00:05:00,69.07217
09 17 2014 01:05:00,637.1816
09 17 2014 02:05:00,0.0
09 17 2014 03:05:00,481.296

I would like to ....
Sep 17, 2014 00:05:00 AM,69.07217
Sep 17, 2014 01:05:00 AM,637.1816
Sep 17, 2014 02:05:00 AM,0.0
Sep 17, 2014 03:05:00 AM,481.296

1 Answer 1

1

Something like this should work:

$dateTime = '09 17 2014 00:05:00'
"{0:MMM dd, yyyy HH:mm:ss tt}" -f [DateTime]::ParseExact($dateTime, 'MM dd yyyy HH:mm:ss', $null)

Outputs:

Sep 17, 2014 00:05:00 AM

Although if you want AM/PM shouldn't you use the 12-hour clock e.g. hh?

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry about, the data file is daily file, can the $dateTime dynamic variable?
That's the whole point of a vari-able. :-) You can assign to the $dateTime the various date fields you read from the CSV file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.