Solved

# Delphi countdown time

Posted on 2008-11-06
1,128 Views
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
Question by:Kevinfeening

LVL 16

Expert Comment

Hi Kevinfeening.

Check this out :
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21984259.html

procedure TForm1.Button1Click(Sender: TObject);

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';

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

LVL 16

Accepted Solution

I'm not very sure if i got the copy(from, to) right because i cant check it right now.
0

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

#### 737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!