How to get the number of the day from the beginning of the year to a given date in Python

3 Answers

0 votes
from datetime import datetime
  
days= datetime.now().timetuple().tm_yday

print(days)


 
'''
run:
 
136
 
'''

 



answered May 16, 2023 by avibootz
edited Dec 13, 2025 by avibootz
0 votes
from datetime import date
 
dt = date(2023, 5, 16)
 
days = dt.strftime('%j')

print(days)



'''
run:

136

'''

 



answered May 16, 2023 by avibootz
0 votes
from datetime import date
  
days = date(2023, 5, 16).timetuple().tm_yday

print(days)
 
 
 
'''
run:
 
136
 
'''

 



answered May 16, 2023 by avibootz
edited Dec 13, 2025 by avibootz

Related questions

...