Overview:
- The maximum time duration that can be represented using the timedelta class is provided by the attribute timedelta.max.
- Trying to create a timedelta of greater than the timedelta.max will result in a overflow.
Example:
# Example Python program that prints from datetime import timedelta # Obtain maximum time duration possible through timedelta # Try creating a timedelta bigger than timedelta.max |
Output:
Maximum timedelta: 999999999 days, 23:59:59.999999 <class 'datetime.timedelta'> Traceback (most recent call last): File "/Valli/PythonProgs/td_ex2.py", line 14, in <module> print(timedelta(timedelta.max.days + 1)) OverflowError: days=1000000000; must have magnitude <= 999999999 |