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

Bo Berglund bo.berglund at gmail.com
Mon Apr 24 20:08:01 CEST 2023

I have a device that sends data over the serial port with a timestamp in this


This is coded as yymmddhhnnss and the last char designates daylight savings
(S)ummer or normal (W)inter time. In the example above it is W for normal winter

What I have done so far is:
- Remove the () at start and end
- Remove the W at the end
- Add 20 (as the century) up front
- Insert a space after the 6th char (so between date and time
- Set the TFormatsettings like this (to say that there are no separators):
  FS.DateSeparator := #0; (Is this how it is done?)
  FS.TimeSeparator := #0;
- Then the call:
  Value := StrToDateTime(sValue, FS); (Value is declared as TDateTime)

This triggers an exception with the message:
 "194522" is not a valid time

What is the proper way to decode a string as shown above?
Since the date part could be decoded, why not also the time part, after all I
separated the two with a space and set the same separators?

Bo Berglund
Developer in Sweden

More information about the fpc-pascal mailing list