How to get Month Name Short Version using Python datetime?

Python datetime – Get Month Name Short Version

To get Month Name Short Version using Python datetime, call strftime() with %b passed as argument.

MonthOutput
JanuaryJan
FebruaryFeb
MarchMar
AprilApr
MayMay
JuneJun
JulyJul
AugustAug
SeptemberSep
OctoberOct
NovemberNov
DecemberDec

Example 1: Get Month Name Short Version of Current Date

In the following example, we will take the current date, and get the day of month.

#import datetime package
import datetime

#get current time
d = datetime.datetime.now()

#print date
print(d)

#get month name short version
print(d.strftime("%b"))
Run this program ONLINE

Output

2019-06-26 08:50:36.787821
Jun

Example 2: Get Month Name Short Version of Specific Date

In the following example, we will take a date 2019-08-12 and get the day of month.

#import datetime package
import datetime

#set specific date
d = datetime.datetime(2019, 8, 12)

#print date
print(d)

#get month name short version
print(d.strftime("%b"))
Run this program ONLINE

Output

2019-08-12 00:00:00
Aug

Summary

In this tutorial, we extracted the month name short version from date using datetime package.