You could use strftime
with a %j
format string:
>>> import datetime
>>> today = datetime.datetime.now()
>>> today.strftime('%j')
'065'
but if you wish to do comparisons or calculations with this number, you would have to convert it to int()
because strftime()
returns a string. If that is the case, you are better off using DzinX's answer.