CDT CDT - 7 months ago 98
C++ Question

Qt - Get the time span between two datetime objects

I have two datetime objects, say, "2013-06-13 11:00:45", "2013-06-14 09:03:23".

How can I get the time span between these two datetimes(in the form of "X days, X hours, X minutes, X seconds")?


Currently, you must use QDateTime::secsTo and then do the math to figure out the days, hours, minutes and seconds.

However, there are plans to add a QTimeSpan class to Qt:

It isn't clear when this will get added to Qt; the merge request is almost 2 years old already. However, you can grab the code from the above merge request and compile it into your project if you'd like.