Day of the Week

In Python, we have a built-in module called datetime that allows us to create, manipulate, and work with dates and times. This problem can be solved by creating a datetime object with the given day, month, and year, and then using the strftime function to format the date object to the day of the week.

Here’s the Python solution:

1
2
3
4
5
6
7
8
9
from datetime import datetime

class Solution:
    def dayOfTheWeek(self, day: int, month: int, year: int) -> str:
        # Create a date object
        date = datetime(year, month, day)

        # Return the day of the week
        return date.strftime("%A")

The strftime function takes one parameter, a format string, and returns a string representing the date. “%A” is a directive that gets replaced by the full weekday name. The other directives you can use with strftime can be found in Python’s official documentation.