SQLite with Powershell - SQLite Datatyp Date is being transferred into DateTime in Powershell

Viewed 183

I'm connecting to an SQLite Database with the system.data.sqlite.org binaries.

At the end, I'm querying my database with

$adapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter $sql
$data = New-Object System.Data.DataSet
[void]$adapter.Fill($data)

Generally, this is working pretty fine but if you have an SQLite Data type Date its being imported into PowerShell as DateTime which is adding 00:00:00 as timestamp.

Can this be avoided? I would like to have the Date as dd-mm-yyyy in PowerShell without the timestamp. For timestamp fields I want to have the date + timestamp of course, but not for the date data types.

Thanks

1 Answers

There is no "Date" datatype in .NET (look here), only DateTime (or DateTimeOffset). Even the Date property on a DateTime object will return another DateTime (with the time component set to 00:00:00).

If you want that particular format, you can format the value as a string:

$datetimevalue.ToString("dd-MM-yyyy")
Related