I am quite a beginner programmer. I am trying to code a to-do list.
My problem is that when I want to do a “time until” section of the to-do list, getting the time until is my problem
#Set current and due date
deadline = f"{year}-{month}-{day} {hour}:{minute1}:{seconds}"
timenow = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
#Format dates
time_now = datetime.strptime(timenow, '%Y-%m-%d %H:%M:%S')
final_deadline = datetime.strptime(deadline, '%Y-%m-%d %H:%M:%S')
diff = final_deadline - time_now
dates = relativedelta(time_now, final_deadline)
print(dates)
My problem is when I print relativedelta it comes out like this for example:
relativedelta(months=-1, days=-2, hours=-1, minutes=-48, seconds=-30)
I want to format it to say 1 month, 2 days, 1 hour, 48 minutes and 30 seconds.
I have tried to use strftime and strptime but they both say they are incompatible with relativedelta.
user25689472 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.