# [Tutor] time question

Lloyd Kvam lkvam@venix.com
Thu, 23 Aug 2001 11:26:45 -0400

```Is there any reason for not using MxDateTime?
http://www.lemburg.com/files/python/mxDateTime.html

It may be overkill for your purposes, but I would think that's generally better than the alternatives.

Rob Andrews wrote:
>
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582

```