[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1163
  • Last Modified:

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
0
Kevinfeening
Asked:
Kevinfeening
  • 2
1 Solution
 
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
 
CodedKCommented:
I'm not very sure if i got the copy(from, to) right because i cant check it right now.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now