python date to day of year code example

Example 1: date.month date time

import datetime
dt = datetime.datetime.today()
print dt.year
# Output: 2016

print dt.month
# Output: 8

print dt.day
# Output: 22

Example 2: python datetime day of year

from datetime import datetime

day_of_year = datetime.now().timetuple().tm_yday

Example 3: python weekday

df['date_time'].dt.dayofweek #gives only the index(0-monday,6-sunday)
df['date_time'].dt.weekday_name #gives the day