Skip to content

Commit dae0bf7

Browse files
authored
Add files via upload
1 parent 7864fd5 commit dae0bf7

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

days/01-03 datetime/pybites_128.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from datetime import datetime
2+
3+
THIS_YEAR = 2018
4+
5+
date_val = '31 Oct, 1958'
6+
7+
date_to_convert = '18/02/2014'
8+
9+
def years_ago(date):
10+
"""Receives a date string of 'DD MMM, YYYY', for example: 8 Aug, 2015
11+
Convert this date str to a datetime object (use strptime).
12+
Then extract the year from the obtained datetime object and subtract
13+
it from the THIS_YEAR constant above, returning the int difference.
14+
So in this example you would get: 2018 - 2015 = 3"""
15+
new_date = datetime.strptime(date, '%d %b, %Y')
16+
return THIS_YEAR - new_date.year
17+
18+
19+
def convert_eu_to_us_date(date):
20+
"""Receives a date string in European format of dd/mm/yyyy, e.g. 11/03/2002
21+
Convert it to an American date: mm/dd/yyyy (in this case 03/11/2002).
22+
To enforce the use of datetime's strptime / strftime (over slicing)
23+
the tests check if a ValueError is raised for invalid day/month/year
24+
ranges (no need to code this, datetime does this out of the box)"""
25+
convert_date = datetime.strptime(date, '%d/%m/%Y')
26+
final = convert_date.strftime('%m/%d/%Y')
27+
return final
28+
29+
print(years_ago(date_val))
30+
31+
print(convert_eu_to_us_date(date_to_convert))

days/01-03 datetime/pybites_67.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from datetime import date, timedelta
2+
3+
start_100days = date(2017, 3, 30)
4+
pybites_founded = date(2016, 12, 19)
5+
pycon_date = date(2018, 5, 8)
6+
7+
8+
def get_hundred_days_end_date():
9+
"""Return a string of yyyy-mm-dd"""
10+
tdelta = timedelta(days=100)
11+
return str(start_100days + tdelta)
12+
13+
14+
15+
def get_days_between_pb_start_first_joint_pycon():
16+
"""Return the int number of days"""
17+
datediff = pycon_date - pybites_founded
18+
return datediff.days
19+
20+
print(get_hundred_days_end_date())
21+
22+
print(get_days_between_pb_start_first_joint_pycon())

0 commit comments

Comments
 (0)