0

I'm reading time into a variable from a CSV file but some of the time like 9 am is written as 9:00 instead of 09:00. How can I correct it into HH: mm format?

1 Answer 1

1

This should do the trick:

('9:00' -as [datetime]).ToString('HH:mm')

You can see it working on a loop from 0:00 to 12:00 with this:

PS /~> 0..12|%{("$_`:00" -as [datetime]).ToString('HH:mm')}
00:00 
01:00 
02:00 
03:00 
04:00 
05:00 
06:00 
07:00 
08:00 
09:00 
10:00 
11:00 
12:00 

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

Comments

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.