0

In my small script I wanted to give script task time. In small time like under 1 min, I give min as -999999999.

But there is no problem in others. Seconds and microseconds can be got and they are int type, though min <class 'datetime.timedelta'>

My related code bunch is:

 from datetime import datetime,timedelta

 now = datetime.now()
 # some code here
 then = datetime.now()

 delta= then-now
 print(delta.seconds) # 10
 print(delta.microseconds) # 432214     
 print(delta.min) # '-999999999 days, 0:00:00'

In the console I give:

datetime.timedelta(days=-999999999)

Where am I doing wrong?

Abhishek Jaisingh
  • 1,614
  • 1
  • 13
  • 23
dose
  • 43
  • 1
  • 3

2 Answers2

0

Only days, seconds and microseconds are stored internally in a timedelta objects

The min attribute that you are accessing does not represent minutes and is actually the most negative timedelta object, timedelta(-999999999)

You can get the value of minutes using the total_seconds method from the timedelta object:

minutes = delta.total_seconds() / 60

Read documentation about min attribute here

Abhishek Jaisingh
  • 1,614
  • 1
  • 13
  • 23
0

timedelta.min doesn't give you minutes, but according to the documentation the smallest possible delta value.

timedelta.min

The most negative timedelta object, timedelta(-999999999).

Talon
  • 1,775
  • 1
  • 7
  • 15