Skip to content

Commit a8d06a8

Browse files
committed
#14 - Python
1 parent 1cf5d60 commit a8d06a8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from datetime import datetime
2+
3+
# Ejercicio 1
4+
current_date = datetime.now().strftime("%d/%m/%Y, %H:%M:%S")
5+
current_date_obj = datetime.strptime(current_date, "%d/%m/%Y, %H:%M:%S")
6+
7+
birth_date = "17/05/1998, 03:25:32"
8+
birth_date_obj = datetime.strptime(birth_date, "%d/%m/%Y, %H:%M:%S")
9+
10+
years_passed = current_date_obj - birth_date_obj
11+
12+
print(f"Birth date: {birth_date_obj} \nCurrent date: {current_date_obj}")
13+
print(f"{years_passed.days//365} years have passed.")
14+
15+
16+
# Ejercicio Extra
17+
print(f"""
18+
Dates Formatting - 10 different ways:
19+
1) [day month year, hour AM/PM] -> {birth_date_obj.strftime("%A %B %Y, %-I %p")}
20+
2) [day-month-year] -> {birth_date_obj.strftime("%a-%b-%Y")}
21+
3) [day day moth, week week_year of year] -> {birth_date_obj.strftime("%A %d %B, week %W of %Y")}
22+
4) [day/month/year, hours:minutes:seconds AM/PM] -> {birth_date_obj.strftime("%-d/%-m/%y, %I:%-M:%-S %p")}
23+
5) [hour AM/PM, year/month/day] -> {birth_date_obj.strftime("%-H %p, %Y/%B/%d")}
24+
6) [day, day of month year] -> {birth_date_obj.strftime("%A, %-d of %B %Y")}
25+
7) [hour AM/PM - month day year] -> {birth_date_obj.strftime("%-H %p - %B %A %Y")}
26+
8) [month/day/year] -> {birth_date_obj.strftime("%b/%d/%Y")}
27+
9) [month.day.year] -> {birth_date_obj.strftime("%m.%d.%y")}
28+
10) [day, year.month.day ; hours:minutes:seconds] -> {birth_date_obj.strftime("%A, %y.%m.%d ; %H:%M:%S")}""")

0 commit comments

Comments
 (0)