# [Tutor] time question

Rob Andrews rob@jam.rr.com
Thu, 23 Aug 2001 10:13:47 -0500

```Okay, I'll admit my ignorance. (It's pretty well documented by now.
heehee)

I'm working on an application to track the progress of someone who has
quit smoking (or to provide info for someone thinking of quitting), and
the whole application is based around the passage of time for its
calculations.

If anyone wishes to risk going blind by actually reading this
alpha-release-wannabe source file, it's located here:

http://www.lowerstandard.com/python/pyQuit.py

But fortunately I have a nice, specific question. After user input, I
have the quit time stored thusly:

>>> import time
>>> quitTime
(2001, 8, 22, 9, 45, -1, -1, -1, -1)

I then convert this to a float, and determine the difference between the
current time and the quitting time:

>>> quitTime1 = time.mktime(quitTime)
>>> currentTime = time.time()
>>> quitTime1
998491499.0
>>> currentTime
998578178.33000004
>>> timeDifference = currentTime - quitTime1
>>> timeDifference
86679.330000042915

At this point, I face the slightly tedious task of converting this time
difference (expressed in seconds) into something more tangible. I'd like
to report "You have been nicotine free for 6 weeks, 5 hours, and 4
minutes." (for example). So far, this means a several-step process of
dividing the seconds down into years, then the remainder down to (lunar)
months, then to weeks, days, and minutes.

Does anyone know a way to do this more directly, elegantly, or briefly?

Rob
--
A mind is a terrible thing. And it must be stopped. Before it kills
someone.
Useless Python!
http://www.lowerstandard.com/python

```