Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c5004a2

Browse files
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

Lines changed: 36 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /