Recent

Author Topic: Calculating hours  (Read 2493 times)

Tirans

  • New Member
  • *
  • Posts: 11
Calculating hours
« on: June 09, 2021, 11:18:23 am »
Hello, i cant seem to figure out how to calculate hours for a specific person. Does anyone have any ideas or tips on how should i tackle this problem?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. const
  3.   mask = 'mm/dd/yyyy"," hh:nn:ss AM/PM';
  4.   lekcijas = 7;
  5. var
  6.   Lines, list: TStringList;
  7.   s: string;
  8.   i: integer;
  9.   d, atnaca, aizgaja: TDateTime;
  10.   fs: TformatSettings;
  11.  
  12. begin
  13.   Lines := TStringList.Create;
  14.   Lines.Loadfromfile('apm.csv');
  15.   list := TStringList.Create;
  16.   setLength(Fails, Lines.Count);
  17.  
  18.   list.delimiter := ';';
  19.   list.strictdelimiter := True;
  20.  
  21.   for i := 1 to High(Fails) do
  22.   begin
  23.     list.DelimitedText := Lines[i];
  24.     with Fails[i] do
  25.  
  26.     begin
  27.       Vards := list[0];
  28.       if pos('(', Vards) > 0 then
  29.         Vards := leftstr(Vards, pos('(', Vards) - 2);
  30.       if (combobox1.items.indexof(Vards) < 0) then
  31.         combobox1.items.add(Vards);
  32.       Darbiba := not (list[1] = 'Left');
  33.  
  34.       s := list[2];
  35.       fs := DefaultFormatSettings;
  36.       fs.DateSeparator := '/';
  37.       laiks := ScanDateTime(mask, s, fs);
  38.     end;
  39.   end;                
  40.  

I have managed to get the time read in the memory correctly and that works all fine, but now i need to figure out how would i calculate total hours for a person https://gyazo.com/48797ac202108236a0cd012fd1e178e1 The file that is read in looks like this and it has joined/left for every person in each day that the meeting took place. Any advice would be appriciated.

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Calculating hours
« Reply #1 on: June 09, 2021, 11:58:47 am »
HoursBetween function in DateUtils unit
Best regards / Pozdrawiam
paweld

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Calculating hours
« Reply #2 on: June 09, 2021, 12:53:41 pm »
Hi!

Code: Pascal  [Select][+][-]
  1. var StartDate, EndDate : TDateTime;
  2. hours : single;
  3.  
  4. hours := (EndDate-StartDate) / 24;
  5.  
  6.  
done

Winni



wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Calculating hours
« Reply #3 on: June 09, 2021, 01:25:01 pm »
Code: Pascal  [Select][+][-]
  1. var StartDate, EndDate : TDateTime;
  2. hours : single;
  3.  
  4. hours := (EndDate-StartDate) / 24;
done
No: times 24: hours := (EndDate-StartDate) * 24;
« Last Edit: June 09, 2021, 02:54:37 pm by wp »

 

TinyPortal © 2005-2018