Hi soonhuat ong,
As stated by others, 12:30:00 AM is correct. The difference between 14:30
and 14:00 is 30 minutes. When you format 30 minutes with the TimeToStr
function, Delphi uses the LongTimeFormat global variable to format the
time. In most systems, the LongTimeFormat is "h:mm:ss AMPM". So, 30
minutes from midnight is "12:30:00 AM". When you want is to show the time
in military format. Here are two ways for you to get "00:30" instead of
"12:30:00 AM":
1. Change LongTimeFormat to 'hh:mm'. This will affect all time formatting
in your program.
procedure TForm1.Button1Click(Sender: TObject);
var Time1, Time2 : TTime;
begin
Time1 := strToTime('14:00');
Time2 := strToTime('14:30');
LongTimeFormat:= 'hh:mm';
ShowMessage(TImeToStr(Time2 - TIme1)); {This will show "00:30"}
ShowMessage(TImeToStr(Time1 - Time2)); {This will show "00:30"}
end;
2. Use FormatDateTime instead of TimeToStr.
procedure TForm1.Button1Click(Sender: TObject);
var Time1, Time2 : TTime;
begin
Time1 := strToTime('14:00');
Time2 := strToTime('14:30');
ShowMessage(FormatDateTime('hh:mm', (Time2 - TIme1))); {This will
show "00:30"}
ShowMessage(FormatDateTime('hh:mm', (Time1 - TIme2))); {This will
show "00:30"}
end;
Hope this helps
Raymond
soonhuat ong
<[EMAIL PROTECTED]
.com>
Sent by:
[EMAIL PROTECTED]
oups.com
06/29/2005 02:45
AM
Sorry i mean Time3 - Time4. Anyway, TIme4- Time3 will generate the same
result.
I'll give my sample source code as following:
procedure TForm1.Button1Click(Sender: TObject);
var Time1, Time2 : TTime;
begin
Time1 := strToTime('14:00');
Time2 := strToTime('14:30');
ShowMessage(TImeToStr(Time2 - TIme1));
ShowMessage(TImeToStr(Time1 - Time2));
end;
Both of the MessageBox give me the message : 12:30:00 AM .. All i want is
00:30, means 30 minutes differences
Vahan Yoghoudjian <[EMAIL PROTECTED]> wrote:
Do you mean (Time4-Time3) or (Time3-Time4)?
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] Behalf
Of soonhuat ong
Sent: Wednesday, June 29, 2005 7:52 AM
To: [email protected]
Subject: [delphi-en] differences between 2 time value
How do i calculate the differences between 2 time ?
Let's say:
Time1 = 13:00
Time2 = 12:00
The difference is 1:00 hour
I try (Time1 - Time2), and it works fine..
But when the total difference less than 1 hour, it give me difference
result:
For eg:
Time3 = 14:30
TIme4 = 14:00
(Time4 - Time3) will give me 12:30 .. what i want is 00:30. ANy idea ??
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/