-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
32 lines (20 loc) · 899 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#JEITO 1
#from datetime import date
#data_niver = "10/05/1988"
#current_date = date.today()
#print("A idade é : ",current_date - data_niver)
#======================= TENTANDO SUBTRAIR OS DATETIMES E APANHANDO LEGAL KKKKK ====================================================
#JEITO 2
import json
from datetime import datetime
current_date = datetime.today()
def idade(current_date):
with open('data.json') as json_file:
for line in json_file:
user = json.loads(line)
date_birthday = datetime.strptime(user["data_nascimento"], '%d/%m/%Y').date()
# niver = date_birthday.strftime('%d/%m/%Y')
date_today = datetime.strftime(current_date, "%Y")
date_niver = datetime.strftime(date_birthday, "%Y")
print("A idade é:",int(date_today) - int(date_niver))
idade(current_date)