implementation {$R *.dfm} // // Date and Time Support on your HELP SYSTEM! // // ALL DATE AND TIME IS STORED INTERNALLY USING A DOUBLE VALUE // THEN YOU CAN CALCULATE IT AS ANY VALUE NUMERIC! // // DONT FORGET OF "Date Time" RANGE, ACCEPTED BY DELPHI, OF COURSE! // uses DateUtils; procedure TForm1.Button1Click(Sender: TObject); var lDateTimeStart : TDateTime; lDateTimeEnd : TDateTime; lDateTimeEncoded: TDateTime; // // ... hh, mm, ss, zzz = all in milliseconds values! Use "word" type, because this value goes to 0..65535 lYears : word; lMonths : word; lDays : word; lHours : word; lMinutes : word; lSeconds : word; lMilliSec: word; // lDaysDouble : Double; lMilliSecsDouble: Double; begin // // StrDateTime dont use "milliseconds" try other function! // // format in Brazil! dd/mm/yyyy // // using default function in your IDE: lDateTimeStart := StrToDateTime('14/02/2020 00:00:01'); { 00:00:00.000 or dont inform to equal to '' } lDateTimeEnd := StrToDateTime('15/03/2020 00:00:00'); { 00:00:00.000 } // // see all other functions this unit for easy calculate! // // Using new funtions in DateUtils.pas unit! lDays := DateUtils.DaysBetween(lDateTimeEnd, lDateTimeStart); // dif between to dates include time lDaysDouble := DateUtils.DaySpan(lDateTimeEnd, lDateTimeStart); // Returns the number of days (including fractional days) between two specified TDateTime values. // ... etc to Months and Year ... and time values // if value have "a rest" then, this "rest is a "TIME" value! // // Try change the value of "time" above for one or two vars lDateTime... if not(lDays = lDaysDouble) then // days.hours-fraction begin lMilliSecsDouble := DateUtils.MilliSecondSpan(lDateTimeEnd, lDateTimeStart); // 0.nnnnnn // // lHours := DateUtils.HourOf(lMilliSecsDouble); ... etc! // // decoding a TDateTime value or your value in format "n.m" DecodeDateTime(lMilliSecsDouble, lYears, lMonths, lDays, lHours, lMinutes, lSeconds, lMilliSec); ShowMessage(Format('%d/%d/%d %d:%d:%d:%d', [lYears, lMonths, lDays, lHours, lMinutes, lSeconds, lMilliSec])); // // from here, you have a "AV" because "Years, Months, Days" is = 0/0/0 == Invalid Date! you need verify this! // // one way: // lDays := 01; // lMonths := 01; // lYears := 01; // lDateTimeEncoded := EncodeDateTime(lYears, lMonths, lDays, lHours, lMinutes, lSeconds, lMilliSec); // DateUtils.RecodeDateTime(lDateTimeEncoded, lYears, lMonths, lDays, lHours, lMinutes, lSeconds, lMilliSec); // // or // ShowMessage(FormatDateTime('01/01/01 hh:mm:ss.zzz', lDateTimeEncoded)); // other way... // or // ShowMessage(DateTimeToStr(lDateTimeEncoded)); // // SUMMARYING: THERE IS MANY OTHER FUNCTION IN YOUR IDE - OTHER MORE EASY THAN THESE! // READ YOU HELP! end; end;