Web Analytics

Python datetime.strftime() Method

Date & Time Format Date

The strftime() method converts a datetime object to a string, according to a given format.

Syntax

datetime_object.strftime(format)

Parameters

Parameter Description
format Required. A format string to define how the result string should look.

Common Format Codes

Code Description Example
%a Weekday, short version Wed
%A Weekday, full version Wednesday
%w Weekday as a number 0-6 3
%d Day of month 01-31 31
%b Month name, short version Dec
%B Month name, full version December
%m Month as a number 01-12 12
%y Year, short version, without century 18
%Y Year, full version 2018
%H Hour 00-23 17
%M Minute 00-59 41
%S Second 00-59 08

Return Value

A string representing the date.

Example

Using the strftime() method:

Output
Click Run to execute your code

Related Functions