datetime to minutes python code example
Example 1: datetimes to day of year python
>>> import datetime
>>> today = datetime.datetime.now()
>>> print today
2009-03-06 15:37:02.484000
>>> today.strftime('%j')
'065'
Example 2: python datetime weekday
from datetime import datetime
date_str='10-12-20'
datetime_object = datetime.strptime(date_str, '%m-%d-%y')
datetime_object.weekday()
Example 3: datetime.strftime() syntax
from datetime import datetime
date_string = "21 June, 2018"
print("date_string =", date_string)
print("type of date_string =", type(date_string))
date_object = datetime.strptime(date_string, "%d %B, %Y")
print("date_object =", date_object)
print("type of date_object =", type(date_object))