+1 vote
in Programming Languages by (26.1k points)
How can I find the day of the week for any given date in Python?


8/2/2022 : Tuesday

1 Answer

+3 votes
by (121k points)
selected by
Best answer

The strftime() function of the datetime module takes a parameter to format the output.

You can specify the parameter '%a' for the shorter version (e.g. Wed) of the day and '%A' for the full version (e.g. Wednesday).

Here is an example:

>>> from datetime import datetime
>>> d=datetime(1998,12,3)
>>> d.strftime("%a")
>>> d.strftime("%A")
>>> d=datetime(2022,8,2)
>>> d.strftime("%A")
>>> d.strftime("%a")