#1 2019-11-21 21:48:43

ertank
Member
Registered: 2016-03-16
Posts: 168

Faster StrToDate()

Hello,

I am using Delphi 10.3.3.

I probably used wrong selection of words using google. SynCommons.pas seems not having that function.

I am searching for a faster running code than current System.SysUtils.StrToDate().

There is below function in my code base and when I used a profiler, it turned out to be time consuming function in the application (most likely because mos of the calls are raising exception I think but not sure).

function IsDate(const DateString: string): Boolean;
begin
  try
    StrToDate(DateString);
    Result := True;
  except
    Result := False;
  end;
end;

So, I am searching for a faster executing code than above.

Offline

#2 2019-11-21 22:52:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Faster StrToDate()

You can use TryStrToDate() from SysUtils.pas (IIRC): it won't raise any exception, so it will be much faster if the supplied text is not a valid date.

But there are so many date format around, that there is no easy replacement...
In SynCommons.pas we have ISO-8601 very fast conversion functions, e.g. IsIso8601() or Iso8601ToTimeLogPUTF8Char() - which work from UTF-8 text.
You can write your own function from their code.

Offline

Board footer

Powered by FluxBB