[datetime] converting date string incorrectly

Hi r/Powershell.

I’ve got a string called $testdate that contains a date and time. It looks like this: ’01/11/2018 22:59:00′ (1st Nov 2018 – UK format). I want to convert it to a datetime type so I can easily compare it with the results of a Get-Date.

I’ve been using [datetime]$testdate to convert it, but it misunderstands the formatting and converts it to ’11 January 2018 22:59:00′ where as it should be ’01 November 2018 22:59:00′.

Is there a way to tell [datetime] that it’s a UK format date so it converts it properly? Or, is there an altogether better way of converting in this instance?

Thanks in advance!

submitted by /u/Iain83
[link] [comments]

Leave a Reply