Find the day of week with a given date in Python

Ever tried to find the day in a week using a date given in Python?
It is a tedious task to do on the paper. Hence I come up with a program to do this job. In this tutorial, we will learn about How to find the day of a week using a date given in Python.
And also look some examples to understand the code.

datetime module to find the day of a week in Python

The program for this tutorial is given below. Keep reading to find insides of this program.

import datetime
week_days= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday']
l=list(map(int, input("Enter date \n eg: 05/05/2019 \n\n").split('/')))[2],l[1],l[0]).weekday()

Let us look at the program.

First of all import the datetime module

import datetime

The list

week_days= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday']

is the list of weekdays.


The input statement in third line takes the input ( eg: 05/05/2019)

input("Enter date \n eg: 05/05/2019 \n\n").split('/')

It gives the output of a list with date, month, year in string format ( [‘date’, ‘month’ , ‘year’])


The function in the statement, month, date)

takes the integer values in place of year, month and date, since we are using these values from the list ‘l’, it must contain integers.

The function map() converts the list of strings to the list of integers.


The statement[2],l[1],l[0]).weekday()

gives an integer(0-6) as the output.

The variable ‘day’ stores this value.
This value is related to the day of a week as follows.

Monday = 0
Tuesday = 1
Wednesday = 2
Thursday = 3
Friday = 4
Saturday = 5
Sunday = 6

Therefore, the statement


prints the corresponding day w.r.t value stored in the variable ‘day’.


Input = 14/06/2019

l = [14, 6, 2019]



Similar programs using datetime module are

How to add days to date in Python

Calculate age in days from date of birth in Python

3 responses to “Find the day of week with a given date in Python”

  1. kuldip says:

    Enter date:15/1/2020
    Traceback (most recent call last):
    File “”, line 37, in[2],1[1],1[0]).weekday()
    TypeError: ‘int’ object is not subscriptable

  2. Aravind Emmadishetty says:

    The above code is correct. It giving exact results to me. I have checked many times. Try again ! 😉

Leave a Reply

Your email address will not be published. Required fields are marked *