Lazarus

Programming => Databases => Topic started by: Thomas Colvin on May 02, 2017, 07:40:49 pm

Title: Formula for a column or how do I do it
Post by: Thomas Colvin 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
Title: Re: Formula for a column or how do I do it
Post by: RAW 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...  :)
Title: Re: Formula for a column or how do I do it
Post by: valdir.marcos 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;
Title: Re: Formula for a column or how do I do it
Post by: RAW 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...
TinyPortal © 2005-2018