Link to home
Start Free TrialLog in
Avatar of K Feening
K FeeningFlag for Australia

asked on

Delphi countdown time

I Have 2 dates and times
                  hh mm ss    
07/11/2008 02.58.55 PM  from computer date time
09/11/2008 03.15.00 PM from manual input

I want to seup a count down showing the Hours Minutes and Seconds remaining
as the computer time changes

Is there an easy code to use
Avatar of CodedK
CodedK
Flag of Greece image

Hi Kevinfeening.

Check this out :
https://www.experts-exchange.com/questions/21984259/Different-between-dates-time.html

procedure TForm1.Button1Click(Sender: TObject);

    function ReadTime(str:String):TDateTime;
    begin
       result:=EncodeDateTime
                              (StrToInt(Copy(str,1,2)),  // <- the day
                              StrToInt(Copy(str,4,2)),  // <- the month
                              StrToInt(Copy(str,7,4)),  // <- the year
                              StrToInt(Copy(str,12,2)), // <- hour
                              StrToInt(Copy(str,15,2)), // <-minutes
                              StrToInt(Copy(str,18,2)), // <-seconds
                              StrToInt(Copy(str,21,2)));
    end;

var
  s1,s2:String;
  dt1,dt2:TDateTime;
  secDif:LongInt;
  begin
  s1:='07/11/2008 02.58.55 PM';
  s2:='09/11/2008 03.15.00 PM';

  dt1:=ReadTime(s1);
  dt2:=ReadTime(s2);
  secDif:=SecondsBetween(dt1,dt2);

  ShowMessage('Diff. in seconds: '+IntToStr(secDif));

  ShowMessage('Diff: '+IntToStr(secDif div 3600)+' hours, '
              +IntToStr((secDif mod 3600) div 60)+' minutes, '
              +IntToStr((secDif mod 3600) mod 60)+' seconds');
end;

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
If you put this code in a timer event (1 second interval) instead of a button and instead of ShowMessage if you pass it to a label then you have your answer.

Hope this helps.
ASKER CERTIFIED SOLUTION
Avatar of CodedK
CodedK
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial