Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between datetimes in Hours, Mins, Seconds

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

like image 882
Blow ThemUp Avatar asked Oct 23 '12 13:10

Blow ThemUp


People also ask

How do you find the difference between two dates in hours minutes and seconds?

get time() -startDate. gettime())/1000; Log. d("App","difference in hour is"+diff/1000/60/60); Mins = diff/1000/60; Seconds = diff/1000; Using this code I'm getting hours as a correct value.

How do you calculate time difference between hours and minutes?

Compute time difference manuallySubtract all end times from hours to minutes. If the start minutes is higher than the end minutes, subtract an hour from the end time hours and add 60 minutes to the end minutes. Proceed to subtract the start time minutes to the end minutes. Subtract the hours too from end to start.


1 Answers

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]);
like image 181
LU RD Avatar answered Oct 06 '22 00:10

LU RD