Why datetime module is so complicated?

Vlastimil Brom vlastimil.brom at gmail.com
Sun Nov 14 11:59:50 EST 2010


2010/11/14 Zeynel <azeynel1 at gmail.com>:
> It's about a week now I've been trying to convert a datetime object to
> seconds since epoch; the object is set to current time by class Rep()
> in Google App Engine:
>
> class Rep(db.Model):
>    ...
>    mCOUNT = db.IntegerProperty()
>    mDATE0 = db.DateTimeProperty(auto_now_add=True)
>    mWEIGHT = db.FloatProperty()
>
> I want to divide mDATE0 by the integer mCOUNT. I asked the same
> question here previously and also at stackoverflow. So far, I still
> cannot make it work. I would greatly appreciate if someone who is an
> expert in datetime operation in Python could help me understand this
> issue. Thank you.
>
> Latest question in Stackoverlow with link to my original question
> there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple
>
> Previous discussions at comp.lang.python:
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/ac9a2c89bed67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/a5aeb6c40ae08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Hi,
just a try, as it is not completely clear to me, what you are trying
to achieve, as I don't have experiences with the mentioned framework.
It seems to me, that you can only reasonably divide timedeltas, not
the absolute timestamps, it might be something like the following:

>>> april_1st=datetime.datetime(2010, 4, 1, 11, 55, 00)
>>> may_1st=datetime.datetime(2010, 5, 1, 11, 54, 03, 123456)
>>> delta_dates = may_1st - april_1st
>>> delta_in_secs = delta_dates.total_seconds()
>>> delta_in_secs
2591943.123456
>>> delta_in_secs / 5.2
498450.60066461534
>>>

hth,
  vbr



More information about the Python-list mailing list