How to deal with a EConvertError with the message: "is not a valid date format" lazarus / 16-Databases ---------------------------------------------------------------------- ferdinand · 2014-10-07 17:05 Hello, gentlemen: I Am developing a software that imports a CSV file into a Firebird database. The program runs and start to import the file but when the code reaches this line: Code: [Select]SQLQuery1.ParamByName('DATE').AsDate := StrToDate(Datos.Strings[21]); it throws the following exception: Project raised exception class 'EConvertError' with message: '?' is not a valid date format.. I know it happens because the corresponding data in the text file needs to be a date, not a char or string, but my question is what is the best way to deal with it? Thanks in advance. ---------------------------------------------------------------------- Mike.Cornflake · 2014-10-07 17:23 You could always use StrToDateDef (example assumes you don't have data relevant to 1899 ) Code: [Select]var   x: TDateTime; begin   x := StrToDateDef('Helloworld', -1);   If x<>-1 then     ShowMessage('ValidDate'); end; Also, you could have a look at TryStrToDate. Or finally, wrap your code in a Try/Except. ---------------------------------------------------------------------- ferdinand · 2014-10-07 18:57 Thank you very much. StrToDateDef is wonderful