New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Code coach Days between dates (SOLVED)
Hello, I wrote this code but it works only for the first three test cases. I cannot figure out what is the problem. I would apreciate if could help me or at least give me an idea about the problem. Here is the problem: You need to calculate exactly how many days have passed between two dates. Task: Calculate how many days have passed between two input dates, and output the result. Input Format: Two strings that represent the dates, first date should be the older date. Date format: Month DD, YYYY Output Format: A number representing the number of days between the two dates. Sample Input: August 15, 1979 June 15, 2018 Sample Output: 14184 Here is the code: https://code.sololearn.com/c5MXU431EEmv/#c
3 Answers
+ 2
Ok. Thank you. I will try that.
I've tried a solution with time.h but it didn't work. I'll try this again with your advice.
+ 1
I've succeded to do it with time.h
Thank your very much for your help!
Here is the code:
https://code.sololearn.com/caxVrM7IhJAV
+ 1
[Easy way with Python Solved 🥱🥱]
import re
from datetime import datetime
da = input()
de = input()
a = datetime.strptime(da, '%B %d, %Y').strftime('%d/%m/%Y')
b = datetime.strptime(de, '%B %d, %Y').strftime('%d/%m/%Y')
aa = datetime.strptime(a,'%d/%m/%Y')
bb = datetime.strptime(b,'%d/%m/%Y')
diff = bb -aa
print(diff.days)