C# DateTimeKind problem


we habe a table with a field of type DateTime.
Before using SQLCipher the behaviour was:
the DateTime value with DateTimeKind = Unspecified was saved with this DateTimeKind,
in SQLCipher there seems to be an auto conversion to DateTimeKind Local?
After selecting the value from db, the kind isn’t Unspecified anymore?

I also tried to set useTicks in connection to false or true, but without any effect.

The workaround is to set the kind to UTC before writing to db
DateTime.SpecifyKind((DateTime)activityEntity.Properties[“StartdateTime”].Value, DateTimeKind.Utc)


Hello @Markus_Reich

I believe you are using the SQLite.Net-PCL client library, is that correct? If so, the client library will always store DateTime values in UTC however, depending on how you initialize your SQLiteConnection instance it will map those values to either local time or remain in UTC.

Yes we use

  • SQLCipher.Net.WinRT80-PCL.3.4.0
  • SQLite.Net.Core-PCL.3.1.1

but I see a different behaviour.
In the debugger I can see that the datetime object has kind => Unspecified
I write this date to the db, when selecting the date again, I get the same ticks, but kind => Local

with non Cipher Sqllite the kind Unspecified is kept as Unspecified?

very strange, it took a long time of debugging, to find this out :frowning:

Hi @Markus_Reich

I’m sorry for any confusion this has caused. The behavior will depend on what value you provide to the 3rd parameter to the SQLiteConnection constructor.