Write a Python Program to Print Year & Short Version of Month
Introduction
In Python, we can use the datetime module to get the current year and month. The month can be displayed in short format like Jan, Feb, Mar, etc.
Logic to Write the Code
- Start the program.
- Import the
datetimemodule. - Get the current date.
- Extract the year.
- Print the year and short month using
strftime("%b"). - End the program.
Source Code (Beginner Friendly)
# Python program to print current year and short version of month
import datetime
# Getting current date
today = datetime.datetime.now()
# Extracting year and short month
year = today.year
month = today.strftime("%b")
# Printing result
print("Year:", year)
print("Month (Short):", month)
Sample Output
Year: 2026
Month (Short): Feb
(Output may vary depending on current date.)
Viva Questions with Answers
1. Which module is used to get date and time in Python?
The datetime module.
2. What does %b represent in strftime()?
It represents the short month name.
3. How do you get the current date in Python?
By using datetime.datetime.now().
4. How do you extract the year from the current date?
By using .year attribute.
5. Can we print full month name instead of short?
Yes, by using %B in strftime().
