CDT CDT -4 years ago 452
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")?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download