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
KevinfeeningAsked:
Who is Participating?
 
CodedKConnect With a Mentor Commented:
I'm not very sure if i got the copy(from, to) right because i cant check it right now.
0
 
CodedKCommented:
Hi Kevinfeening.

Check this out :
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21984259.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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.