pythonarrow-python

Get day of year from python arrow


_date = '2017-03-17T00:00:00'

import arrow
arrow.get(_date)

How can I get day of year from the above code?


Solution

  • You are asking for the arrow solution, but here as an alternative with datetime library.

    As explained by: Converting python time stamp to day of year this would be the answer you are seeking:

    import datetime
    _date = '2017-03-17T00:00:00'
    dt = datetime.datetime.strptime(_date, '%Y-%m-%dT%H:%M:%S')
    print(dt.timetuple().tm_yday)
    # prints 76