I have an application that use sqlite as local database, but I have problems with the format of the dates.
I am using System.Data.Sqlite as database provider and I create my edmx, that is created from the sqlite database.
When I make a query to the database, in my entity class that has some date field, I can see that the dateTime property has the correct format, in my case, dd mm yyyy and 18:00 (the hour is of 24 hours, not 12pm for example).
However, when I do the binding (I am using WPF and MVVM) to the dataGrid, in the columns of date the format of the date is mm dd yyyy 12pm (the hour is not of 24).
Why?, if I receive the data in the correct format, because the entity object has de date in the correct format I see the information in other format in the dataGrid? When I use SQL Server as dataBase, I don’t have this problem, the format is correct in the dataGrid.
My windows is configurated to ES (Spain).
Thanks.
I would guess that the problem is with the DateTime.Kind property. Dates can be Local, UTC, or unknown. Check that the date is restoring from the database with the same Kind-ness, and if not, adjust your Sqlite connection parameters to use the Kind you wish to work with.
The proper way to handle this, in my opinion, is to always store dates/times as UTC in the database and always query against the database using equivalent UTC representation. You can set the DateTime kind to UTC in the Sqlite connection settings. You can ensure that your objects have local times in your property setter if you want the objects to always represent times that way, like so:
Which should ensure that times stay local after being loaded from the database.