Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-04

Problem with DateTimeToStr at midnight?

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hello,

i use DateTimeToStr from unit sysutils.

At midnight the Date and Time format is wrong (time is missing), is n't?

For example:
20-4-07 23:57
20-4-07 23:58
20-4-07 23:59
21-4-07
21-4-07 00:00
21-4-07 00:01
21-4-07 00:02

The line "21-4-07" ist at 00:00:00 and the line "21-4-07 00:00" is later or equal then 00:00:01!

Is this ok?

Here is same sample source to demonstrate:

---

program error_datetimetostr;
uses
  crt,sysutils;
var
  timeroffset:TDateTime;
begin
  (* I will add an offset thru now-function so it is 5 seconds before midnight *)
  timeroffset:=1-frac(now)-5/86400;
  while not(keypressed) do
  begin
    writeln(DateTimeToStr(now+timeroffset)); (* Write the time by adding some offset-seconds*)
  end;
end.