DateUtils on Windows and on Linux (Debisn) lazarus / 21-General ---------------------------------------------------------------------- lado · 2023-05-12 07:02 Both on Windows 11 and on Linux I use the same version of FPC/Lazarus (3.2.2/2.2.6). The following code works Ok in Windows:   dtnow := Copy(DateTimeToStr(Now), 1, 10) + ' 00:00:00';   Result := DateTimeToStr( the following code(StrToDateTime(dtnow), millisec));  But the same code raises EConvertError saying "08 00:00:00" is not a valid time when executing the Result:= ... line Digging into info about datetime utils gave me no answer on how to solve or work around this issue ---------------------------------------------------------------------- alpine · 2023-05-12 07:12 It is probably because of different DefaultFormatSettings. Use FormatDateTime with a predefined format string. ---------------------------------------------------------------------- wp · 2023-05-12 08:06 Trying to guess what you want to achieve... The first line indicates that you seem to want to obtain the datetime of the start of the current day. That's what the function Date() would be doing without string conversion, or, for an arbitrary date: 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 Function StartOfTheDay(const AValue: TDateTime): TDateTime; But what is "millisec"? ---------------------------------------------------------------------- ASBzone · 2023-05-12 16:07 Quote from: lado on May 12, 2023, 09:02:29 amBoth on Windows 11 and on Linux I use the same version of FPC/Lazarus (3.2.2/2.2.6). The following code works Ok in Windows:   dtnow := Copy(DateTimeToStr(Now), 1, 10) + ' 00:00:00';   Result := DateTimeToStr( the following code(StrToDateTime(dtnow), millisec));  But the same code raises EConvertError saying "08 00:00:00" is not a valid time when executing the Result:= ... line Digging into info about datetime utils gave me no answer on how to solve or work around this issue Can you provide an actual code snippet that compiles? I suspect that it is the format of the string that is a problem, but we'd benefit from seeing the code itself. ---------------------------------------------------------------------- lado · 2023-05-12 18:06 Hi, I realize that I should give a more complete code snippet when I asked the question. Sorry about that. So the code is as follows: 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 function UnpackDateTime(arr: TBytes): string;var  ba: array[0..3] of byte;  millisec: Integer;  dtnow: string;  i: integer;begin  for i := 0 to 3 do    ba[i] := arr[3-i];  millisec := Integer(ba);  //millisec := 23460000;  dtnow := Copy(DateTimeToStr(Now), 1, 10) + ' 00:00:00';  Result := DateTimeToStr(IncMilliSecond(StrToDateTime(dtnow), millisec));end; The function receives an input of 4 bytes in arr. The bytes are then reversed into ba (to take care of little endian) and converted to millisec integer value which stands for number of milliseconds since midnight. The millisecs are added to start of day and converted to date time string. If I force the millisec value to 23460000 for test, I get datetime string 12/05/2023 06:31:00 (on Windows). Of course the date part of the string is the current date ---------------------------------------------------------------------- wp · 2023-05-12 20:18 This is the way how I would do it: 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 function UnpackDateTime(arr: TBytes): String;var  ba: array[0..3] of byte;  millisec: DWord;  i: integer;begin  for i := 0 to 3 do    ba[i] := arr[3-i];  millisec := DWord(ba);  Result := DateTimeToStr(IncMillisecond(Date(), millisec));  //  Result := FormatDateTime('c.zzz', IncMilliSecond(Date, millisec));  // Use this if you want milliseconds in the result stringend;As you may notice the date-to-string conversion is avoided by using the TDate result of the Date() function immediately. Next I declare millisec as an unsigned integer (DWord) rather than a signed integer: Usually the amount of milliseconds will be so small that there is no overflow into the negative range, but better safe than sorry... (and it documents that you are expecting a positive number here). ---------------------------------------------------------------------- lado · 2023-05-12 21:22 Hi wp, your suggestion works perfectly both on Windows and Linux platforms. Thanks for the tip on date() function. The code fixed your way is also simpler and more readable. In this case, casting millisec to DWord instead Integer does not seem important, but like you say: better safe than sorry. I'll certainly review my code and change it the ways you taught me. I am aware that I have a lot of serious holes in my Free Pascal knowledge as I only recently started using it. My only previous experience was in the early seventies on PDP 11 and RSX OS Pascal and very limited too. Picking knowledge on Free Pascal/Delphi online is tedious as infos are scattered and sometimes obsolete.. I guess I'll have to get the Lazarus handbook sooner or later in order to have a decent Pascal reference at the reach of my hands.