Is StrToDate supposed to fail on '2021/3/10'? lazarus / 62-General ---------------------------------------------------------------------- EganSolo · 2021-03-12 06:42 The following piece of code fires an exception. Is this normal? Should StrToDate fail on '2021/3/10' (March 10, 2012)? 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; Var S : String = '2021/3/10';    D : TDate             ;    Error: Boolean  = False ;Begin  Try    D := SysUtils.StrToDate(S);  Except On E: Exception do     begin       Writeln('Invalid date: ', S);       Error := true;     End;  End;  If Not Error  then Writeln('Date is ', D);  Readln;End. ---------------------------------------------------------------------- balazsszekely · 2021-03-12 06:56 @EganSolo QuoteThe following piece of code fires an exception. Is this normal? Should StrToDate fail on '2021/3/10' (March 10, 2012)?Before the conversion, you should specify the date format: 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 //..FormatSettings.ShortDateFormat:='YYYY/MM/DD';D := SysUtils.StrToDate(S);//.. ---------------------------------------------------------------------- dseligo · 2021-03-12 07:00 It's dependent on your locale: "The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the ShortDateFormat variable." You can change it as GetMem said. https://www.freepascal.org/docs-html/rtl/sysutils/strtodate.html ---------------------------------------------------------------------- EganSolo · 2021-03-12 07:22 Got it! Thanks once more, GetMem! ---------------------------------------------------------------------- MarkMLl · 2021-03-12 08:37 Quote from: GetMem on March 12, 2021, 07:56:01 am@EganSolo QuoteThe following piece of code fires an exception. Is this normal? Should StrToDate fail on '2021/3/10' (March 10, 2012)?Before the conversion, you should specify the date format: 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 //..FormatSettings.ShortDateFormat:='YYYY/MM/DD';D := SysUtils.StrToDate(S);//.. In what locale is that format valid? Obligatory XKCD: https://xkcd.com/1179/ MarkMLl ---------------------------------------------------------------------- Remy Lebeau · 2021-03-12 17:41 Quote from: GetMem on March 12, 2021, 07:56:01 amBefore the conversion, you should specify the date format: 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 //..FormatSettings.ShortDateFormat:='YYYY/MM/DD';D := SysUtils.StrToDate(S);//.. Unless your app is single-threaded, you should not use the global FormatSettings like that.  Pass a local TFormatSettings directly to StrToDate() instead, eg: 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 var Fmt: TFormatSettings;SysUtils.GetLocaleFormatSettings(0, Fmt);Fmt.ShortDateFormat := 'YYYY/MM/DD';D := SysUtils.StrToDate(S, Fmt);