Timedelta

Timedelta:

The Timedelta() class:

- The timedelta() class is used to represent the difference between two datetime objects.

- The timedelta() class is also used to add or subtract days, hours, minutes, seconds, and microseconds in a datetime object

- The years and months are NOT changed by timedelta() class.



- In the below codes, the * (sign in import) means calling all classes of the datetime module at one time.

- In the below codes, we add one second by using the timedelta() class.




In the below codes, we add one day and one second by using the timedelta() class.


The Negative timedelta() class:

- In the below codes, we subtract one week by using the negative value in the timedelta() class.



In the below codes, we subtract one week by subtracting the timedelta and datetime variables in the print() function.

Comments