Convert datetime string from proxy log to datetime object

Hi everybody. I have a script that I’ve written with a really kludgy DateTime conversion. It works, but I know it’s wrong.

I have a string that I parse out of a proxy log that looks like this” 05/Mar/2018:14:09:40

Get-Date says it can’t convert it because it’s not a valid DateTime. I save it as variable called $DateTime and then do this:

$DateTime = $DateTime.split(":")[0] + " " + $DateTime.split(":")[1] + ":" + $DateTime.split(":")[2] + ":" + $DateTime.split(":")[3] [DateTime]$DateTime = get-date $DateTime 

That works, but there’s got to be a better way to turn the original string into a DateTime object.


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

Leave a Reply