• 0
Sign in to follow this  
Jhonas

Somar total de horas entre 2 datas

Question

OBS: o comando SecondsBetween é do Delphi 7

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses DateUtils;

{$R *.dfm}

//Função converter Segundos para Horas

function Seg_Hora( Seg:LongInt ):string;
Var Hora,Min:LongInt;
  Tmp : Double;
begin
   Tmp := Seg / 3600;
   Hora := Round(Int(Tmp));
   Seg :=  Round(Seg - (Hora*3600));
   Tmp := Seg / 60;
   Min := Round(Int(Tmp));
   Seg :=  Round(Seg - (Min*60));
   Result := FormatFloat( '00', Hora )+ ':' + FormatFloat( '00', Min ) + ':' + FormatFloat( '00', Seg );
end;


procedure TForm1.Button1Click(Sender: TObject);
var total : int64; ini, fim : TDateTime;
begin
   ini := strtodatetime(Edit1.Text);
   fim := strtodatetime(Edit2.Text);

   total := SecondsBetween(ini,fim);
   Label1.Caption := 'Tempo Total : '+ seg_hora(total);
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
   edit1.Text := '13/10/2010 13:25:10';
   edit2.Text := '14/10/2010 15:33:15';
end;

end.

abraço

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this