### Author Topic: Formula for a column or how do I do it  (Read 1329 times)

#### Thomas Colvin

• New member
• Posts: 11
##### Formula for a column or how do I do it
« on: May 02, 2017, 07:40:49 pm »
Am making a table. One column is my salesman's name the next what city he is working the next the product he is doing the next is the date he was there (using date like 05/02/2017) and the next column is the date he went back.

Now what I want is the next column to say how many days between his visits.

In Excel the formula is cell1 in column B minus cell1 in column A. And I set column C cell1 to number and it show the number of days.

But what do I do in Delphi to make my column show the days between visits?

Thomas

#### RAW

• Hero Member
• Posts: 664
##### Re: Formula for a column or how do I do it
« Reply #1 on: May 02, 2017, 08:27:57 pm »
Take a look at TDateTime...
There are a lot of examples out there. TDateTime is DOUBLE I guess and so you can easily calculate the difference between two dates...
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.2 FPC 3.0.4 // 1.7 FPC 3.1.1

#### valdir.marcos

• Sr. Member
• Posts: 379
##### Re: Formula for a column or how do I do it
« Reply #2 on: May 02, 2017, 08:46:09 pm »
Maybe this example helps:
Code: Pascal  [Select]
1. uses
2.   ..., dateutils;
3.
4. procedure TForm1.Button1Click(Sender: TObject);
5. var
6.   BeginDate, EndDate: TDate;
7.   WorkedDays: Integer;
8. begin
9.   BeginDate := StrToDate('01/01/2017');
10.   EndDate   := Now;
11.   WorkedDays := DaysBetween(EndDate, BeginDate);
12.   ShowMessage('WorkedDays: ' + IntToStr(WorkedDays));
13. end;

#### RAW

• Hero Member
• Posts: 664
##### Re: Formula for a column or how do I do it
« Reply #3 on: May 02, 2017, 09:17:43 pm »
Code: Pascal  [Select]
1. Procedure TForm1.FormClick(Sender: TObject);
2.   Var
3.    Date1,
4.    Date2: TDateTime;
5.    iDays: Integer;
6.  Begin
7.   Date1:= StrToDate('25.10.2000');
8.   Date2:= Now;
9.
10.   iDays:= Trunc(Date2-Date1); // Round results in 1 day more :-)
11.
12.   ShowMessage(IntToStr(iDays));
13.   ShowMessage(IntToStr(DaysBetween(Date2, Date1)));
14.  End;
15.

There is also DAYSPAN... maybe interesting too...
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.2 FPC 3.0.4 // 1.7 FPC 3.1.1