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
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.
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.
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]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With