Reputation: 191
I want to add time only as HH:MM to MS Access in Delphi. It is shown as '21:21:00' in the Access table but it shows up as '30.12.1899 21:21:00' in my dbgrid.
ADOTable1.Active:=FALSE;
ADOTAble1.Open;
ADOTable1.Insert;
ADOTable1time.Value:=Strtotime(MaskEdit1.Text);
ADOTable1.post;
ADOTable1.Active:=TRUE;
Note: I changed editmask option to short time of TMaskEdit1 Thank in advance.
Upvotes: 1
Views: 2031
Reputation: 416
You can do it programatically, after you open the dataset:
TDateTimeField (FieldByName ('Time')).DisplayFormat:='HH:mm';
Upvotes: 0
Reputation: 27385
The data is correctly stored, it's just not displayed as you would like.
The Date/Time in Access as the Delphi TDateTime
is storing casually spoken
the date in the integer part and the time in the fractional part.
To get the Time shown as desired just set the DisplayFormat
property of your field to hh:nn:ss
.
In the pictures below you can see the always same field formatted, not formatted and as float.
Upvotes: 4
Reputation: 123809
You need to tweak the formatting for that column of your dbgrid to only show the time component. Access only has a Date/Time
column type (it does not have separate Date
and Time
column types) so a Date/Time
value entered without a date part is stored as 1899-12-30 hh:mm:ss
. If you are only interested in the time part then you just need to format the dbgrid column appropriately. (Access automatically does that for you in its own controls, ref: here.)
Upvotes: 3