Recent

Author Topic: Minimum and maximum value of TDateTime  (Read 466 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 388
Minimum and maximum value of TDateTime
« on: November 12, 2025, 08:28:51 pm »
What is the minimum and maximum values of TDateTime?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

BrunoK

  • Hero Member
  • *****
  • Posts: 747
  • Retired programmer
Re: Minimum and maximum value of TDateTime
« Reply #1 on: November 12, 2025, 08:44:29 pm »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. uses
  3. SysUtils;
  4.  
  5. begin
  6.   writeln(DateTimeToStr(MinDateTime), ' - ', DateTimeToStr(MaxDateTime));
  7.   readln;
  8. end.

LemonParty

  • Sr. Member
  • ****
  • Posts: 388
Re: Minimum and maximum value of TDateTime
« Reply #2 on: November 12, 2025, 08:51:22 pm »
I was searching MinDateTime and MaxDateTime values in DateUtils unit.
Thank you.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

dsiders

  • Hero Member
  • *****
  • Posts: 1491
Re: Minimum and maximum value of TDateTime
« Reply #3 on: November 12, 2025, 09:05:00 pm »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. uses
  3. SysUtils;
  4.  
  5. begin
  6.   writeln(DateTimeToStr(MinDateTime), ' - ', DateTimeToStr(MaxDateTime));
  7.   readln;
  8. end.

And if you notice, the comment in the FPC 3.2.2 source code does not match the actual value in MinDateTime.

Comment says:

Code: Pascal  [Select][+][-]
  1. MinDateTime: TDateTime =  -693593.99999999; { 01/01/0001 12:00:00.000 AM }

The output value from FormatDateTime says:
Code: Pascal  [Select][+][-]
  1. 01/01/0001 23:59:59.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Thaddy

  • Hero Member
  • *****
  • Posts: 18475
  • Here stood a man who saw the Elbe and jumped it.
Re: Minimum and maximum value of TDateTime
« Reply #4 on: November 13, 2025, 08:18:08 am »
A suggestion to rephrase the comment ( from CoPilot ) which is correct is:
"MinDateTime: TDateTime = -693593.99999999;
{ Represents 01-Jan-0001 at 23:59:59, using the day-fraction convention
  (integer = days offset from 30-Dec-1899, fraction = time of day). }
"
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

ASerge

  • Hero Member
  • *****
  • Posts: 2468
Re: Minimum and maximum value of TDateTime
« Reply #5 on: November 13, 2025, 07:30:38 pm »
Maybe change the value of MinDateTime to 693593.0?

Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2. {$IFDEF WINDOWS}
  3.   {$APPTYPE CONSOLE}
  4. {$ENDIF}
  5.  
  6. uses DateUtils;
  7.  
  8. const
  9.   Date1 = -693593.99999999;
  10.   Date2 = -693593.0;
  11. begin
  12.   Writeln('Double1 < Double2: ', Date1 < Date2);
  13.   Writeln('DateTime1 < DateTime2: ', CompareDate(Date1, Date2) < 0);
  14.   Write('Press Enter to exit...');
  15.   Readln;
  16. end.

For TDateTime types, the fractional part is always assumed positive, so the negative time part must be processed using its absolute value.


 

TinyPortal © 2005-2018