How to get Weekday Short Version using Python datetime?

Python datetime – Get Weekday Short Version

To get Weekday Short Version using Python datetime, call strftime() with %a passed as argument.

Example 1: Get Weekday Short Version of Current Date

In the following example, we will take the current date, and get the short version of the weekday.

#import datetime package
import datetime

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

#print date
print(d)

#get the weekday short version
print(d.strftime("%a"))
Run this program ONLINE

Output

2019-06-26 08:01:34.116109
Wed

Example 2: Get Weekday Short Version of a Specific Date

In the following example, we will take a date 2019-08-12 and get the short version of the weekday.

#import datetime package
import datetime

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

#print date
print(d)

#get the weekday short version
print(d.strftime("%a"))
Run this program ONLINE

Output

2019-08-12 00:00:00
Mon

Summary

In this tutorial, we extracted the short version of weekday using datetime package.