Converting OpenInsight Date Time to Powershell Date Time
This is a walk through showing the conversion of Date Time values to a Powershell Date Time value.
If you generate your Date Time values in OpenInsight with this format:
OIDateTime = Oconv(Date(),'D2/') : " " : Oconv(Time(),'MTHS')
You'll get a value looking like this:
12/07/15 01:54:37PM
Powershell can convert this format to an internal format with the Get-Date command:
$PSDateTime = Get-Date $OIDateTime
The variable $PSDateTime contains .NET date time reference.
As a bonus, it now becomes much easier to convert the date time value to other formats. Here is an example to convert the value to MySQL DateTime string:
$MySQLDateTime = Get-Date $PSDateTime -Format "yyyy-MM-dd HH:m:ss"
The variable $MySQLDateTime now contains a string "2015-12-07 13:54:37" which can be easily inserted into a standard MySQL datetime column.
Leave a comment