Search code examples
mysqldelphifiredac

Editing datetime fields in MySQL using Delphi and firedac


I am using Delphi 10.1 and Firedac components to connect to a MySQL database. Using live bindings or the VCL data aware components I can edit the data in the MySQL tables except for dates (e.g. invoice date). I understand there is a type difference between the Delphi TDateTime and MySQL DateTime in ISO format but I can't work out how or where to undertake a conversion? Any assistance greatly appreciated.

Many thanks

Matt


Solution

  • You can add a data type mapping for the TFDConnection mapping dtTimeStamp into dtDateTime. Something like:

    with FDConnection1.FormatOptions.MapRules.Add do begin
      SourceDataType := dtTimeStamp;
      TargetDataType := dtDateTime;
    end;