T
T
Tokenchik2017-01-19 08:12:53
Pascal
Tokenchik, 2017-01-19 08:12:53

How to count the number of days between dates?

There is a small form with a couple of TEdits, in which you need to enter two dates, and then enter the number of days between these dates into a separate variable.
I'm getting data from forms, and casting a string to a date, then I'm trying to use the Daysbetween function, but something goes wrong,

....
  ed1,ed2:String;
  daysbet: Integer;
  ed3,ed4: TDateTime;
  ....
  ed1:= Edit1.text;
  ed2:= Edit2.text;
  ed3:= StrToDate(ed1);
  ed4:= StrToDate(ed2);
  daysbet:=DaysBetween(ed3,ed4);

UPD: an error was found, the DateUtils module is not included in uses.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2017-01-19
@Tokenchik

You can do without DaysBetween. By themselves, TDateTime is a fractional number, where the integer part is days and the fractional part is time. Those. normal integer(day1 - day2)will return the difference in days.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question