![]() Now we will see hot to add or subtract a time object with all the time components with a datetime object. So far, we have seen how to add and subtract individual time component like hours or minutes or seconds from a datetime object. Print("After subtracting microseconds: ", datetime_new, "\n")Īdding and subtracting datetime object with time object Print("After subtracting seconds: ", datetime_new, "\n")ĭatetime_new = datetime_new - timedelta(microseconds = microseconds_to_add) Print("After subtracting minutes: ", datetime_new, "\n")ĭatetime_new = datetime_new - timedelta(seconds = seconds_to_add) ![]() Print("After subtracting hours: ", datetime_new, "\n")ĭatetime_new = datetime_new - timedelta(minutes = minutes_to_add) # Subtracting hours or minutes or seconds to datetimeĭatetime_new = datetime_original - timedelta(hours = hours_to_add) To perform subtraction of individual time components from datetme object, just create a timedelta object with the time component and then subtract from the datetime object. Print("After adding microseconds: ", datetime_new, "\n") Print("After adding seconds: ", datetime_new, "\n")ĭatetime_new = datetime_new timedelta(microseconds = microseconds_to_add) Print("After adding minutes: ", datetime_new, "\n")ĭatetime_new = datetime_new timedelta(seconds = seconds_to_add) Print("After adding hours: ", datetime_new, "\n")ĭatetime_new = datetime_new timedelta(minutes = minutes_to_add) Print("\nOriginal date: ", datetime_original, "\n")ĭatetime_new = datetime_original timedelta(hours = hours_to_add) # Adding hours or minutes or seconds to datetimeĭatetime_original = datetime(year=2006, month=11, day=23)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |