Format date in database grid

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
hmc
Posts: 1
Joined: Tue 17 Jan 2017 07:05

Format date in database grid

Post by hmc » Tue 26 Dec 2017 22:21

I have not been able to successfully format a date value in a Delphi database grid column. The underlying dataset is displayed using a TLiteQuery, a TLiteDataSource and a standard Delphi TDBGrid.

The date value is the Delphi tDateTime value stored as a double in LiteDac dataset field 1. In a test dataset with four records, the date values are stored as 43000, 43000.2, 43096 and 43096.1. Time of day is not needed, only the date.

This test instruction works, and proves the four double float values can be accurately retrieved from the dataset:
tNumericField(fmOpen.dbgDateList.DataSource.Dataset.Fields[1]).DisplayFormat := '#,##0.0000';

This instruction does not work (the displayed date value in grid column[1] is literally dd/mm/yyyy for every record in the query result):
tDateTimeField(fmOpen.dbgDateList.DataSource.Dataset.Fields[1]).DisplayFormat := 'dd/mm/yyyy'

I am using D14 (2009). I have tested my D14 version of Delphi using the console test posted in this forum by MaximG on Wed 13 Jan 2016 14:31. D14 correctly formats the date and time in the console output.

Since I know that Delphi can retrieve the date value as a numeric, the formatting problem appears to be within the tDateTimeField formatting instruction when it is applied to a LiteDAC component dataset.

The grid is used for display and selection purposes, and no value (date or otherwise) is edited directly within the grid.

Any help would be appreciated. I have a simple Delphi app and simple SQLite3 database used to test the date value formatting, and I am happy to share it.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Format date in database grid

Post by MaximG » Thu 01 Feb 2018 08:18

Please specify the type of the column whose data is displayed incorrectly? Do you set the option

Code: Select all

LiteConnection1.Options.NativeDate: = False;
in this case ?

Post Reply