I have a text file
11/11/2020 11:23:45 Text2 12345
Text 2020-11-25 11:23:46 12345
I am looping through the text file and I need output for line 1 as 11/11/2020 11:23:45 by specifying date format as "MM/dd/yyyy HH:mm:ss" and for line 2 as 2020-11-25 11:23:46 by specifying date format as "yyyy-dd-MM HH:mm:ss"
$pattern = "MM/dd/yyyy HH:mm:ss"
$dateString = 11/11/2020 11:23:45 Text2 12345
$date = [datetime]::ParseExact($dateString,$date_format,$null)
I cannot use regex as there might be quite few number of date formats in the text file and parseExact is not working as the string has other values combined with Date.
Any help please!!