Lazarus comparing Dates

0

In the data collector I can configure the Data format, but I want to do this setting inside my application, I am trying to do it as follows:

FormatSettings.ShortDateFormat := 'dd-mm-yy';
ShowMessage(QueryTesteDT_PALLET.Text); // Resultado: '06-07-17'
if QueryTesteDT_PALLET.Value <= StrToDate('30-06-17') then
....

I have the following error: "30-06-17" is not a valid date format.

I'm using Lazarus for development.

    
asked by anonymous 06.07.2017 / 21:29

2 answers

0

I've never used Lazarus, though ...

  

if QueryTestDT_PALLET.Value

15.07.2017 / 04:52
0

You must pass the FormatSettings that you have set as the StrToDate function's parameter. You must also assign the tab you want to use to the attribute FormatSettings.DateSeparator.

The StrToDate function is overloaded, so you can use it in two ways:

The first form receives only the string and converts to date with the standard ShortDateFormat format. function StrToDate (const S: string): TDateTime; overload;

The second way to use the function, is to get the string to be converted and the FormatSettings to use. function StrToDate (const S: string; const FormatSettings: TFormatSettings): TDateTime; overload;

Following Usage example:

procedure TForm1.Button1Click(Sender: TObject);
var
  Data: TDateTime;
  FormatSettings: TFormatSettings;
  begin
    FormatSettings.DateSeparator := '-';
    FormatSettings.ShortDateFormat := 'dd/mm/yyyy';
    Data := StrToDate('01-06-2017', FormatSettings);
    ShowMessage(DateToStr(Data));
end;
    
08.03.2018 / 12:41