[Solved] ScanDateTime error in Sep lazarus / 21-General ---------------------------------------------------------------------- ALAU2007 · 2025-06-09 02:39 I convert string '01 Sep 2025' to date, it shows:   Can't match any allowed value at pattern position 4, string position 4 The other month is OK, only the Sep has error: procedure TForm1.Button1Click(Sender: TObject); var tDate: TDateTime; begin   tDate := scandatetime( 'dd mmm yyyy', '01 Jan 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 sep 2025' );  // Error   ShowMessage( DateToStr( tDate )); end; Please comment. ---------------------------------------------------------------------- dsiders · 2025-06-09 03:51 Quote from: ALAU2007 on June 09, 2025, 04:39:07 amI convert string '01 Sep 2025' to date, it shows:   Can't match any allowed value at pattern position 4, string position 4 The other month is OK, only the Sep has error: procedure TForm1.Button1Click(Sender: TObject); var tDate: TDateTime; begin   tDate := scandatetime( 'dd mmm yyyy', '01 Jan 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 sep 2025' );  // Error   ShowMessage( DateToStr( tDate )); end; Please comment. Does you system use English month names in FormatSettings.ShortMonthNames? Cause that's what you told ScanDateTijme() to look for. ---------------------------------------------------------------------- paweld · 2025-06-09 04:41 As @dsiders wrote, probably your system's regional settings are not English. You need to define an array of short month names in English 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 uses  DateUtils; procedure TForm1.Button1Click(Sender: TObject);var  s: String;  dt: TDateTime;  fs: TFormatSettings;begin  fs := DefaultFormatSettings;  //if your system locale is not in English, then you need to define short month names  fs.ShortMonthNames[1] := 'Jan';  fs.ShortMonthNames[2] := 'Feb';  fs.ShortMonthNames[3] := 'Mar';  fs.ShortMonthNames[4] := 'Apr';  fs.ShortMonthNames[5] := 'May';  fs.ShortMonthNames[6] := 'Jun';  fs.ShortMonthNames[7] := 'Jul';  fs.ShortMonthNames[8] := 'Aug';  fs.ShortMonthNames[9] := 'Sep';  fs.ShortMonthNames[10] := 'Oct';  fs.ShortMonthNames[11] := 'Nov';  fs.ShortMonthNames[12] := 'Dec';  //  s := '01 Jan 2025';  dt := ScanDateTime('d mmm yyyy', s, fs);  ShowMessage(DateToStr(dt));  //  s := '01 sep 2025';  dt := ScanDateTime('d mmm yyyy', s, fs);  ShowMessage(DateToStr(dt));end; ---------------------------------------------------------------------- ALAU2007 · 2025-06-09 08:56 Thanks paweld and dsiders. After defining the ShortMonthName, It works.  BTW, I have tried the other months is OK, except the "Sep" has the error.  I have tried as procedure TForm1.Button1Click(Sender: TObject); var tDate: TDateTime; begin   tDate := scandatetime( 'dd mmm yyyy', '01 Oct 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Nov 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Dec 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Aug 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Jul 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Jun 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 May 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Apr 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Mar 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Feb 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 Jan 2025' );   tDate := scandatetime( 'dd mmm yyyy', '01 sep 2025' );   tDate := formatdatetime( 'dd mmm yyyy', '01 sep 2025' );   // only it has error when shortMonthNme is not defined.   ShowMessage( DateToStr( tDate )); end; ---------------------------------------------------------------------- cdbc · 2025-06-09 09:45 Hi Just an observation: - I believe the 'ScanDateTime' function is case-sensitive: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   tDate := scandatetime( 'dd mmm yyyy', '01 sep 2025' );That would mean 'sep' is different from 'Sep'! I noticed all the other months were with a versal, e.g.: '(J)an' --> not '(j)an'. Regards Benny ---------------------------------------------------------------------- paweld · 2025-06-09 10:05 @cdbc: is not case-sensitive - uses the function: https://docs.freepascal.org/docs-html/rtl/sysutils/ansistrlicomp.html Edit: @ALAU2007: you may want to check how you have short month names defined, such as: 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 uses  DateUtils; procedure TForm1.FormCreate(Sender: TObject);var  i: Integer;  s: String;begin  s := '';  for i := Low(DefaultFormatSettings.ShortMonthNames) to High(DefaultFormatSettings.ShortMonthNames) do    s := s + Format('%2d -> %s'#13#10, [i, DefaultFormatSettings.ShortMonthNames[i]]);  ShowMessage(s);end;