Difference between datetimes in Hours, Mins, Seconds

Blow ThemUp picture Blow ThemUp · Oct 23, 2012 · Viewed 19.8k times · Source

I am trying to get the difference between two datetimes and display it in string as hh:mm

q.parambyname('vstart').asdatetime:=  vstart;
q.parambyname('vend').asdatetime:= vend;
d:= vend-vstart;
mins:= d * 1440;
q.ParamByName('mins').asBCD:= mins;

currently the database stores it in minutes

example (0.39)

I would like to then take it from database and display it in the string format hh:mm

Answer

LU RD picture LU RD · Oct 23, 2012

In DateUtils there is a function MinutesBetween which can be used as such:

m := MinutesBetween(vend,vstart);
yourHMStr := Format('%2.2d:%2.2d',[m div 60,m mod 60]);