Skip to content

Commit 0f6e28b

Browse files
committed
mouredev#14 - Python
1 parent 928e11d commit 0f6e28b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import datetime
2+
3+
# Variable para fecha actual
4+
current_datetime = datetime.datetime.now()
5+
6+
datebirth_str = "30-07-2004 02:28:00 AM"
7+
format_str = "%d-%m-%Y %I:%M:%S %p"
8+
9+
# Variable para mi fecha de nacimiento
10+
birth_datetime = datetime.datetime.strptime(datebirth_str, format_str)
11+
12+
# Cálculo de tiempo entre fechas
13+
difference_datetime = current_datetime - birth_datetime
14+
years = difference_datetime.days // 365
15+
remaining_days = difference_datetime.days % 365
16+
months = remaining_days // 30
17+
remaining_days %= 30
18+
days = remaining_days
19+
hours = difference_datetime.seconds // 3600
20+
minutes =(difference_datetime.seconds % 3600) // 60
21+
seconds = difference_datetime.seconds % 60
22+
23+
print(f'''Hi, I'm César and i have:
24+
{years} years, {months} months, {days} days, with
25+
{hours} hours, {minutes} minutes and {seconds} seconds
26+
''')
27+
28+
print(f"""
29+
1. Year-Month-Day Hrs:Min:Sec = {birth_datetime}
30+
2. Day/Month/Year = {birth_datetime.strftime("%d/%m/%Y")}
31+
3. Month/Day/Year = {birth_datetime.strftime("%m/%d/%Y")}
32+
4. Day/MonthName/Year = {birth_datetime.strftime("%d/%B/%Y")}
33+
5. DayName-Dat/MonthName/Year = {birth_datetime.strftime("%A-%d/%B/%Y")}
34+
6. Abbreviated = {birth_datetime.strftime("%a-%d-%b-%Y")}
35+
7. DayName-Day-MonthNameAbbr = {birth_datetime.strftime("%a-%d-%b")}
36+
8. Day of the year = {birth_datetime.strftime("%j")}
37+
9. Hour(12 format) = {birth_datetime.strftime("%I:%M:%S %p")}
38+
10. Hour(24 format) = {birth_datetime.strftime("%H:%M:%S")}
39+
11. {birth_datetime.strftime("%A, %dth of %B %Y at %I:%M:%S %p")}
40+
""")

0 commit comments

Comments
 (0)