Skip to content
Related Articles

Related Articles

Python program to find the first day of given year

View Discussion
Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 27 Jul, 2022
View Discussion
Improve Article
Save Article

Given a year as input, write a Python to find the starting day of the given year. We will use the Python datetime library in order to solve this problem. 

Example: 

Input : 2010
Output :Friday
Input :2019
Output :Tuesday

Below is the implementation: 

Python3




# Python program to find the first day of given year
 
# import datetime library
import datetime
 
 
def Startingday(year):
 
    # Creating an object for 1st January of that particular year
    # For that we are passing three argument (1) year (2) month
    # i.e 1 for january (3) date i.e 1 for starting day of
    # that particular year
    a = datetime.datetime(year, 1, 1)
 
    # for printing Startingday of a particular year
    # we are using a.strftime("% A")
    print( & quot
          Starting day of year & quot
          , year, & quot
          is & quot
           , a.strftime(& quot
                         % A & quot
                         ))
 
 
# Driver Code
year = 2010
Startingday(year)

Output:

Starting day of year  2010  is  Friday

Time Complexity: O(1)

Space Complexity: O(1)

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!