'If conditions with datetime comparisons
def countdown_date(strdate):
datetimeobj = datetime.datetime.strptime(strdate, "%a, %b %d / %H:%M %p %Y")
return datetimeobj - datetime.datetime.today()
My above functions asks for strdate and it expects data similar to this
Sun, Dec 12 / 3:00 AM 2022 and the output will be a remaining count of days and hours til that date.
If the remaining days is a negative amount of days I'd like to increase the datetime object by one year and output the count
How do I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
