
August 2nd, 2006, 12:45 PM
|
|
|
Datetime objects
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.
|

August 2nd, 2006, 12:45 PM
|
|
|
Re: Datetime objects
Lad wrote:
Quote:
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
|

August 2nd, 2006, 01:15 PM
|
|
|
Re: Datetime objects
Sybren Stuvel wrote:
Quote:
Lad enlightened us with:
Quote:
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
datetime.timedelta(0, 52662, 922000) 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
|

August 2nd, 2006, 01:55 PM
|
|
|
Re: Datetime objects
Lad wrote:
Quote:
Sybren Stuvel wrote:
Quote:
Lad enlightened us with:
Quote:
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
>datetime.timedelta(0, 52662, 922000)datetime.timedelta(-999999999)
|
Reread the manual:
1. "min" is minIMUM, not minUTES
2. You need: 0 52662 922000
Quote:
Quote:
Quote:
>>minutes = (diff.seconds + diff.microseconds / 1000000.0) / 60.0
>>minutes
|
|
|
877.71536666666668
Quote:
>
>
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
|

August 2nd, 2006, 04:45 PM
|
|
|
Re: Datetime objects
John Machin wrote:
Quote:
Lad wrote:
Quote:
Sybren Stuvel wrote:
Quote:
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
datetime.timedelta(0, 52662, 922000) datetime.timedelta(-999999999)
|
>
Reread the manual:
>
1. "min" is minIMUM, not minUTES
>
2. You need:052662922000
Quote:
Quote:
>minutes = (diff.seconds + diff.microseconds / 1000000.0) / 60.0
>minutes
|
|
877.71536666666668
Quote:
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
|
Thank you for the explanation
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|