Invalid date lazarus / 21-General ---------------------------------------------------------------------- Tirans · 2021-06-07 21:01 Hello, im making a little project and after i read in the file with all the data ive gotten it all to work except for the last part which is the date/time. It shows me an error message "invalid date" ive tried formatting it, but that didnt seem to fix it, i have a feeling im missing one simple line. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  begin  Lines := TStringList.Create;  Lines.Loadfromfile('apm.csv');  list := TStringList.Create;  setLength(apm, Lines.Count);   list.delimiter := ';';  list.strictdelimiter := True;  DefaultFormatSettings.LongDateFormat:='mm/dd/yyyy, hh:nn:ss AM/PM';  DefaultFormatSettings.DateSeparator := '/';  DefaultFormatSettings.TimeSeparator := ':';   for i := 1 to High(apm) do  begin    list.DelimitedText := Lines[i];    with apm[i] do begin    Cilveks := list[0];      if pos('(', cilveks) >0 then      cilveks:= leftstr(cilveks,pos('(', cilveks)-2);      if (combobox1.items.indexof(cilveks) <0) then      combobox1.items.add(cilveks);      Darbiba := not (list[1] = 'Left');       s:=list[2];      t:= copy2symbdel(s,',');      laiks:= StrToDateTime(t);     end;  end; ---------------------------------------------------------------------- wp · 2021-06-07 21:39 String-to-date conversion by using the StrToDate or StrToDateTime function is often not successful for me when I have a non-standard format string. The main problem is for me that I never know whether the ShortDateFormat or the LongDateFormat of the FormatSettings is used in the conversion (likewise with the time part). It is much clearer to use the ScanDateTime function of the DateUtils unit. Here you specify a mask with the date/time symbols for the back- conversion. Just note that the '/' is replaced by the FormatSettings.DateSeparator, and that non-symbol characters often must be quoted. This works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;uses  SysUtils, DateUtils;const  mask = 'mm/dd/yyyy"," hh:nn:ss AM/PM';  s = '06/07/2021, 11:30:10 pm'; var  d: TDateTime;  fs: TFormatSettings;begin  fs := DefaultFormatSettings;  fs.DateSeparator := '/';  d := ScanDateTime(mask, s, fs);  WriteLn(DateTimeToStr(d));   ReadLnend.