python get day code example
Example 1: python get day name
import datetime
now = datetime.datetime.now()
print(now.strftime("%A"))
Example 2: how to extract month from date in python
import datetime
date = '2021-05-21 11:22:03'
datem = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
print(datem.day)
print(datem.month)
print(datem.year)
print(datem.hour)
print(datem.minute)
print(datem.second)
Example 3: python date get day
import datetime
dt = datetime.datetime.today()
year = dt.year
month = dt.month
day = dt.day
Example 4: python datetime get weekday name
import datetime
now = datetime.datetime.now()
print(now.strftime("%A"))