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.

Month Output
January Jan
February Feb
March Mar
April Apr
May May
June Jun
July Jul
August Aug
September Sep
October Oct
November Nov
December Dec

Examples

1. Get month name short version from current date

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

Python Program

# 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 Code

Output

2019-06-26 08:50:36.787821
Jun

2. Get month name short version from given date

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

Python Program

# 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 Code

Output

2019-08-12 00:00:00
Aug

Summary

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

Related Tutorials

Privacy Policy Terms of Use

SitemapContact Us