Forum > Databases
TbufDataSet, formating a date field
(1/1)
cpalx:
Hello,
how could ia format a field date in TbufDataSet
lucamar:
As with any other dataset: add a field to FieldDefs with the proper type (ftDate, ftTime, ftTimeStamp, ...). You can set it or read it back with Field.AsDateTime.
cpalx:
@lucamar, i wanted to say:
formatdate like 'dd/mm/yyyy' not field type.
wp:
Use the 'DisplayFormat' property of the field. You must cast the field to TDateField, TDateTimeField, or TTimefield to have access to this property.
The following code works with a TBufDataset, TDataSource and a TDBGrid on a form (linked in the usual way):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);var i: Integer; F: TField;begin BufDataset1.FileName := 'data.db'; if not FileExists(BufDataset1.FileName) then begin BufDataset1.FieldDefs.Add('date', ftDate); BufDataset1.CreateDataset; BufDataset1.Open; for i := 0 to 100 do BufDataset1.AppendRecord([Random(365) + EncodeDate(2020, 1, 1)]); end; BufDataset1.Open; F := BufDataset1.FieldByName('date'); if F is TDateField then TDateField(F).DisplayFormat := 'yyyy-mm-dd';end;
Navigation
[0] Message Index