Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Time calculation

Posted on 2001-06-20
Medium Priority
163 Views
Hi,
How can I calculate how many minutes between now and 5 pm the same day ?
Thanks
0
Question by:frdep
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 13

Accepted Solution

Epsylon earned 400 total points
ID: 6211264
Try this:

var date1, date2, diffdate: TDateTime;
difftime: TTime;
hour , min, sec, msec: Word;
ndays: Integer;
begin
date1 := Date + EncodeTime(17, 0, 0, 0);
date2 := Now;
diffdate := date2 - date1;
ndays := Trunc(diffdate);
difftime := diffdate - ndays;
DecodeTime(difftime, hour, min, sec, msec);
hour := hour + ndays * 24;
ShowMessage(IntToStr(hour) + ' hours, ' + IntToStr(min) + ' minutes ' + IntToStr(sec) + ' seconds')
end;
0

LVL 13

Expert Comment

ID: 6211314
If you only need the minutes you can use this:

date1 := Date + EncodeTime(17, 0, 0, 0);
date2 := Now;
ShowMessage(IntToStr(Trunc(Abs(date2 - date1) * 24 * 60)));
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question