-
-
Save ology/c8c0f35cef8968f5d2ba8be0eb05d522 to your computer and use it in GitHub Desktop.
timedelta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime, time, date, timedelta | |
| today = date.today() | |
| print(today) # 2025-09-14 | |
| my_time = time(10, 30, 0) | |
| print(my_time) # 10:30:00 | |
| my_datetime = datetime.combine(today, my_time) | |
| print(my_datetime) # 2025-09-14 10:30:00 | |
| duration_to_subtract = timedelta(minutes=30) | |
| print(duration_to_subtract) # 0:30:00 | |
| new_datetime = my_datetime - duration_to_subtract | |
| print(new_datetime) # 2025-09-14 10:00:00 | |
| new_time = new_datetime.time() | |
| print(new_time_subtract) # 10:00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment