[fpc-pascal] How to use StrToDateTime() to convert a string with no delimiters?

Bo Berglund bo.berglund at gmail.com
Tue Apr 25 21:59:57 CEST 2023


On Tue, 25 Apr 2023 08:25:01 +0200 (CEST), Michael Van Canneyt via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:

>
>
>On Mon, 24 Apr 2023, Thomas Kurz via fpc-pascal wrote:
>
>> I always use ScanDateTime for such purposes:
>>
>> https://www.freepascal.org/docs-html/rtl/dateutils/scandatetime.html
>>
>> You can explicitly define the pattern.
>
>Correct. This is the only correct way to do this.
>
>StrToDateTime is very limited in what it accepts.
>
>Michael.

Thanks, I did not know about this before, but now it is inserted in my code and
works fine. :-)

So now I can just specify the pattern of data to be scanned using the y, m, h, n
and s letters.
But I am adding 20 on front of the telegram value because that uses only a
2-digit year and I had problems on my new RPiZero until I added the two yy in
front of the pattern making it a 4-char year and the 20 in front of the
telegram.

Then all works fine.

-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list