Skip to content

Commit c5004a2

Browse files
committed
completed date_diff
1 parent 392745b commit c5004a2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Day 1/date-diff.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'''
2+
12/04/2019
3+
4+
2018 years
5+
+
6+
3 months
7+
+
8+
12 days
9+
10+
leap year: y / 400 == 0 || (y % 4 == 0 && y % 100 != 0)
11+
12+
year = 413
13+
year//4 - year//100 + year//400
14+
'''
15+
16+
def count_days(date):
17+
months = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
18+
day, month, year = tuple(map(int, date.split('/')))
19+
days = year * 365 + year//400 + year//4 - year//100
20+
21+
for m in range(month):
22+
days += months[m]
23+
24+
days += day
25+
26+
return days
27+
28+
29+
30+
date1 = input("Enter the first date")
31+
date2 = input("Enter the second date")
32+
33+
days1 = count_days(date1)
34+
days2 = count_days(date2)
35+
36+
print(abs(days1 - days2))

0 commit comments

Comments
 (0)