How to Format date using strftime() in Python ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report In this article, we will see how to format date using strftime() in Python. localtime() and gmtime() returns a tuple representing a time and this tuple is converted into a string as specified by the format argument using python time method strftime(). Syntax: time.strftime(format[, sec]) sec: This is the time in number of seconds to be formatted. format: This is the directive or format code which would be used to format. Directive or format code Returned ValuedExample%YFull year with century2021,2022%yYear without century with zero padded value00,01,....21,22...,99%-yYear without century0,1...,99%mMonth with zero padded value01-12%-mMonth without zero padded value1-12%BFull month nameJanuary, February,..., December%bShort form of month Jan, Feb,...,Dec%AFull weekday nameSunday, Monday,..%aShort form of weekday nameSun, Mon,..%wWeekday as decimal value0-6%dDays with zero padded value01-31%-dDays with decimal value1-31%HHour (24-hour clock) as a zero-padded value.00-23%-HHour (24-hour clock) without zero-padded value.0,1,...,23%IHour (12-hour clock) as a zero-padded value.01-12%-IHour (12-hour clock) without zero-padded value.1-12%MMins with zero-padded 00-59%-MMins without zero padded value0-59%SSecs with zero padded value00-59%-SSecs without zero padded value0-59%fMicro Secs with zero-padded value000000 - 999999%pLocale’s AM or PM.AM/PM%jDay of the year with zero padded value001-366%-jDay of the year without zero padded value1-366%zUTC offset in the form +HHMM or -HHMM. %ZTime zone name. %CLocale’s appropriate date and timeFri Apr 02 02:09:07 2020%xLocale’s appropriate date02/04/22%XLocale’s appropriate time02:04:22%WWeek number of the year. Monday as first day of week00-53%UWeek number of the year. Sunday as first day of week00-53 Below are some examples for better understanding. Example 1: Python3 from datetime import datetime # current time and date # datetime object time = datetime.now() print("Without formatting:", time) # formatting date using strftime print("After formatting:", time.strftime("%b %d, %Y")) OutputWithout formatting: 2022-11-29 12:59:08.088819 After formatting: Nov 29, 2022 Output: Example 2: Python3 from datetime import datetime # current time and date # datetime object time = datetime.now() print("Without formatting:", time) # formatting date using strftime print("Year", time.strftime("%Y")) print("Month name", time.strftime("%B")) print("Day", time.strftime("%d")) Output: Example 3: Python3 from datetime import datetime # current time and date # datetime object time = datetime.now() # formatting date using strftime # format = MM/DD/YY print(time.strftime("%m/%d/%y")) # format = Month D, Yr print(time.strftime("%B %d, %Y")) # time formatting # HH:MM:SS print(time.strftime("%H:%M:%S")) Output: Create Quiz Comment M maheswaripiyush9 Follow 2 Improve M maheswaripiyush9 Follow 2 Improve Article Tags : Python Python-datetime Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like