
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to find the first date of a given year using Python?
In this program, we have to print the first day of the year. We have to take a year as a user input.
Algorithm
Step 1: Import the datetime library. Step 2: Take year as input from the user. Step 3: Get the first day of the year by passing month, day and year as parameters to the datetime.datetime() function Step 4: Display the first day using strftime() function.
Example Code
import datetime year = int(input("Enter year: ")) firstday = datetime.datetime(year, 1,1) print("First Day of ", year, " = ", firstday.strftime("%A"))
Output
First Day of 2021 = Friday
- Related Articles
- Write a program in Python to print the day of the year in a given date series
- Python Pandas - Indicate whether the date in DateTimeIndex is the first day of the year
- Program to find maximum population year using Python
- Write a program in Python to split the date column into day, month, year in multiple columns of a given dataframe
- How to Check Leap Year using Python?
- How to find the number of digits in a given number using Python?
- How to find a leap year using C language?
- How to get the same or first day of next month on a given date in Excel?
- How to find all elements in a given array except for the first one using JavaScript?
- Python Pandas - Indicate if the date from the PeriodIndex object belongs to a leap year
- How to convert a date to quarter and year in R?
- Find the index of the first unique character in a given string using C++
- How to find Kaprekar numbers within a given range using Python?
- Java Program to add year to current date using Calendar.add method
- How to detect if a given year is a Leap year in Oracle?

Advertisements