I have the following string which is pulled from an entry in a log file.
$d = "19/09/2014 22:41:27"
However, I need to convert it so that it is
2014-09-19 22:41:27
so that I can export it with other sections of the logfile into a MySQL database.
But I can't for the life of me find a way to do this. I was expecting to find something like set-dateFormat, which would simply re-map the components of the string, but it doesn't seem to exist.
I have tried various variations of the following:
$a = "19/09/2014 22:41:27"
$d = [datetime]::ParseExact($a, "dd/MM/yyyy hh:mm:ss", $null)
$e = "{0:yyyymmddhhmmss}" -f [datetime]$d
But everything returns the error:
String was not recognized as a valid DateTime.
What is the best way to get the format I need please?