Datetime objects

L

Lad

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)

Thank you for help
L.
 
D

Diez B. Roggisch

Lad said:
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)

a - b

Lookup datetime.timedelta - all of this is neatly documented.

Diez
 
L

Lad

Sybren said:
Lad enlightened us with:

diff = b - a

Ok, I tried
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
 
J

John Machin

Lad said:
Ok, I tried

datetime.timedelta(-999999999)

Reread the manual:

1. "min" is minIMUM, not minUTES

2. You need:
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?

because toordinal() works only on the date part, ignoring the time
part.

HTH,
John
 
L

Lad

John said:
Reread the manual:

1. "min" is minIMUM, not minUTES

2. You need:

because toordinal() works only on the date part, ignoring the time
part.

HTH,
John
Thank you for the explanation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top