Autor Beitrag
schaumermal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Do 18.11.10 17:41 
Hallo,

kann mir jemand sagen, wie ich Delphi Zeiten über 24 Stunden darstellen kann?

Ich ermittle und summiere die Arbeitszeiten pro Tag.
Wie kann ich es anstellen, dass ich als Ergenis z.B. 38:15 Stunden bekomme.
Nach meiner Addition erhalte ich z.B. hier nur 14:15.

Gruß

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var  Tmp:Double;
begin
    QSuchen.SQL.Text:='Select * from PersonalAnwesenheitszeiten';
    QSuchen.SQL.Add('Where PersonalID='+IntToStr(Personal));
    QSuchen.Active:=true;

    // Zeiten ermitteln
    Tmp:=QSuchen.FieldByName('MontagBis').AsDateTime-QSuchen.FieldByName('MontagVon').AsDateTime;
    Tmp:=Tmp+QSuchen.FieldByName('DienstagBis').AsDateTime-QSuchen.FieldByName('DienstagVon').AsDateTime;
    Tmp:=Tmp+QSuchen.FieldByName('MittwochBis').AsDateTime-QSuchen.FieldByName('MittwochVon').AsDateTime;
    Tmp:=Tmp+QSuchen.FieldByName('DonnerstagBis').AsDateTime-QSuchen.FieldByName('DonnerstagVon').AsDateTime;
    Tmp:=Tmp+QSuchen.FieldByName('FreitagBis').AsDateTime-QSuchen.FieldByName('FreitagVon').AsDateTime;
    Tmp:=Tmp+QSuchen.FieldByName('SamstagBis').AsDateTime-QSuchen.FieldByName('SamstagVon').AsDateTime;
    Result:=DateTimeToStr(tmp);


Moderiert von user profile iconMartok: Delphi-Tags gesetzt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 18.11.10 17:56 
ausblenden Delphi-Quelltext
1:
Result := TimeToStr(Frac(tmp));					
Frac extrahiert den Nachkommaanteil. Und da ein Tag genau Eins entspricht, passt das für die Uhrzeit. Dann noch die Tage mit 24 multiplizieren und addieren.
schaumermal Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Do 18.11.10 17:59 
Hi,

das ist schon klar.
Aber wie kann ich dies dann als 38:15 anzeigen lassen?
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 18.11.10 18:08 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  d,h,mm,s,z:Word;
  Zeit:Double;
begin
   Zeit := 1.7;
   d := Trunc(zeit);
   DecodeTime(Zeit,h,mm,s,z);
   Showmessage(Format('%d:%d',[d*24+h,mm]))
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
schaumermal Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Do 18.11.10 18:10 
Danke!