Datetime objects

Rama ramasubramani.g at gmail.com
Wed Aug 2 08:32:06 EDT 2006


I am a newcomer to python - so not too sure if this method is the correct
one.

Noticing this,

>>> dir(diff)
['__abs__', '__add__', '__class__', '__delattr__', '__div__', '__doc__',
'__eq__
', '__floordiv__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__
', '__le__', '__lt__', '__mul__', '__ne__', '__neg__', '__new__',
'__nonzero__',
 '__pos__', '__radd__', '__rdiv__', '__reduce__', '__reduce_ex__',
'__repr__', '
__rfloordiv__', '__rmul__', '__rsub__', '__setattr__', '__str__', '__sub__',
'da
ys', 'max', 'microseconds', 'min', 'resolution', 'seconds']

it seems

>>> diff.seconds
52662

should give you what you want. Converting the seconds to hours, minutes,
seconds should be easy.

Of course, looking at help(diff), I get the impression that in the generic
case you should check if diff.days == 0 to decide if you should be usingthat
as well.

thank,
Rama



On 2 Aug 2006 05:16:08 -0700, Lad <python at hope.cz> wrote:
>
>
> Sybren Stuvel wrote:
> > Lad enlightened us with:
> > > How can I find days and minutes difference between two datetime
> > > objects?
> > > For example If I  have
> > > b=datetime.datetime(2006, 8, 2, 8, 57, 28, 687000)
> > > a=datetime.datetime(2006, 8, 1, 18, 19, 45, 765000)
> >
> > diff = b - a
>
> Ok, I tried
>
> >>> diff=b-a
> >>> diff
> datetime.timedelta(0, 52662, 922000)
> >>> diff.min
> datetime.timedelta(-999999999)
>
>
> which is not good for me.
>
> So I tried to use toordinal like this
> diff=b.toordinal()-a.toordinal()
>
> but I get
> diff=1
>
> Why?
> where do I make a mistake?
> Thank you for help
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060802/55ff74ed/attachment.html>


More information about the Python-list mailing list