Using timestamp in different fields

2

I have a timestamp field in a postgres table. I would like to treat, in delphi, the date in one dbedit and the time in another, is there that possibility ?? In the tests I performed, I can even change the values but when I exit, for example the dbedit keeps the date, it changes the time and the same happens when I leave the dbedit of the hour, it changes the date.

    
asked by anonymous 08.11.2014 / 13:53

2 answers

1

One of the ways to do this is to not use DBWare components, and use the DataSet AfterScroll and BeforePost events to update your non-DBWare fields.

Given the DataHoraBanco field you can do the following:

First create 2 fields without using DB components ( TEdit, TDateTimePicker, TMaskEdit , etc)

dteDataForm
edtHoraForm

In your dataset in event AfterScroll fill in:

procedure Form1.DataSetonAfterScroll(DataSet: TDataSet);
begin
  dteDataForm.Date := Trunc(DataSet.FieldByName('DataHoraBanco').AsDateTime );
  edtHoraForm.Text := FormatDateTime('hh:nn:ss', DataSet.FieldByName('DataHoraBanco').AsDateTime);
end;

And in event BeforePost do:

procedure Form1.DataSetonAfterScroll(DataSet: TDataSet);
begin
  DataSet.FieldByName('DataHoraBanco').AsDateTime := dteDataForm.Date +
    StrToTime(edtHoraForm.Text);
end;

Remembering that the TDateTime type of delphi is a Double and so the Trunc function extracts the integer (date) and sum, the + sign is used to add the decimal part equivalent to minutes and seconds.

    
10.11.2014 / 13:11
0

In your Select you can create two "virtual" fields, one for time and one for date. Making a cast for date and another for time, from the original field (timestamp). In the BeforePost event of the component you concatenate the two values for the original field.

Example:

Select Cast(CampoTimeStamp as Date) as Campo_Data, Cast(CampoTimeStamp as Time) as Campo_Hora, CampoTimeStamp From...

In the before post event it would look something like this:

DataSet['CampoTimeStamp'] := DataSet['Campo_Data'] + DataSet['Campo_Hora'];
    
08.11.2014 / 18:31