🌐
Python
docs.python.org β€Ί 3.6 β€Ί library β€Ί datetime.html
8.1. datetime β€” Basic date and time types β€” Python 3.6.15 documentation
Return a string representing the time, controlled by an explicit format string. For a complete list of formatting directives, see strftime() and strptime() Behavior.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-strftime-function
Python strftime() function - GeeksforGeeks
July 12, 2025 - from datetime import datetime now = datetime.now() print(now) # Format: Abbreviated weekday, month, 2-digit year f_1 = now.strftime("%a %m %y") print(f_1) # Format: Full weekday, full year f_2 = now.strftime("%A %m %Y") print(f_2) # Format: 12-hour time with AM/PM and seconds f_3 = now.strftime("%I %p %S") print(f_3) # Format: Day of the year f_4 = now.strftime("%j") print(f_4)
🌐
Python documentation
docs.python.org β€Ί 3 β€Ί library β€Ί datetime.html
datetime β€” Basic date and time types
2006 # year 11 # month 21 # day 16 # hour 30 # minute 0 # second 1 # weekday (0 = Monday) 325 # number of days since 1st January -1 # dst - method tzinfo.dst() returned None >>> # Date in ISO format >>> ic = my_datetime.isocalendar() >>> for it in ic: ... print(it) ... 2006 # ISO year 47 # ISO week 2 # ISO weekday >>> # Formatting a datetime >>> my_datetime.strftime("%A, %d.
🌐
strftime
strftime.org
Python strftime reference cheatsheet
A quick reference for Python's strftime formatting directives.
🌐
Quora
quora.com β€Ί What-is-Strptime-and-Strftime-in-Python
What is Strptime and Strftime in Python? - Quora
Answer (1 of 2): You asked: β€˜In Python, what is the difference between strftime() and strptime()?’ Short answer: strftime() is used to convert a time to string. The β€˜time’ must be of a type struct_time which is a β€˜tuple’ or list/array ...
🌐
AskPython
askpython.com β€Ί home β€Ί what is python strftime() function?
What is Python strftime() function? - AskPython
August 6, 2022 - Further, Python strftime() function accepts the time in various forms and returns a string with the time represented as in the standard form.
🌐
Devhints
devhints.io β€Ί others β€Ί strftime format cheatsheet
strftime format cheatsheet
One-page guide to strftime format: usage, examples, and more. The strftime format is the standard date formatting for UNIX. It's used in C, Ruby, and more.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί difference between strftime and datetime??
r/learnpython on Reddit: Difference between strftime and datetime??
August 19, 2017 -

So yesterday I was working with an excel file and I wanted to have a way to include the exact date of that file's creation in the file name. So I used strftime. But I also know that there is a datetime function. Previously, I've never worked with either of these functions, so I can't claim to understand the differences. Which is why I wanted to ask here. What are the differences between these two functions and modules? The time module and the date time module that is.

Top answer
1 of 3
6
datetime gives you an object that is used in python for time representation and manipulation. >>> from datetime import datetime >>> now = datetime.now() >>> now datetime.datetime(2017, 8, 19, 14, 14, 59, 637824) >>> type(now) >>> now - datetime(2000,1,1,0,0,0) datetime.timedelta(6440, 51299, 637824) It doesn't have any format to speak of, it's just a object with numbers for year, month, day, hours, minutes, seconds, and the subsecond crap. You can do math on it. Given that datetime itself has no format, a function capable of doing so is necessary. Strftime (string format time) is that function. It takes the value of the object and produces a string representation in a given format that uses a bunch of %X flags that stand for different things, so you can use that string for printing nice dates and name things with it. >>> now.strftime('%A') 'Saturday' >>> now.strftime('%B') 'August' >>> now.strftime('%Y-%m-%d') '2017-08-19' https://docs.python.org/3/library/datetime.html there is also strptime (string parse time) that goes in the opposite direction - it is capable of parsing a string containing date and produce the kosher datetime object.
2 of 3
2
Time.strftime let's you take all the date/time information and put it in a specific format. It's really useful if you want to output the time, date or both in a specific way. Like I could put out the time in the format: Hour-minute-second time.strftime('%-I-%M-%-S') Or like this Hour:minute:second time.strftime('%-I:%M:%-S') And you can do a lot more with it and add words to it as well time.strftime('Hour%-I:Min%M:Sec%-S') Output: 'Hour11:Min8:Sec5'
Find elsewhere
🌐
Nestria
nestria.org β€Ί pages β€Ί python-strftime
Python datetime.strftime() – Nestria
Python Python strftime() function The strftime() function is used to convert date and time objects to their string representation. It takes one or more input of formatted code and returns the string representation.
🌐
Pythontic
pythontic.com β€Ί datetime β€Ί date β€Ί strftime
The strftime() function in Python | Pythontic.com
The strftime() function of a date instance in Python returns a date string as per the format specified.An example program is given with strftime() output
🌐
Esri Community
community.esri.com β€Ί t5 β€Ί python-questions β€Ί milliseconds-with-strftime β€Ί td-p β€Ί 73258
Solved: Milliseconds with strftime - Esri Community
December 10, 2021 - from datetime import datetime curr_time = datetime.now() formatted_time = curr_time.strftime('%H:%M:%S.%f') print(formatted_time) 18:41:59.891075‍‍‍‍‍‍‍‍‍‍‍‍‍‍ Β· How to get min, seconds and milliseconds from datetime.now() in Python
🌐
Tutorialspoint
tutorialspoint.com β€Ί python β€Ί time_strftime.htm
Python time strftime() Method
February 17, 2009 - Similar to the Python time asctime() method, the strftime() method also converts a tuple or struct_time representing, either in UTC or the local time, to a 24-character string of the following form: 'Mon Jan 9 10:51:77 2023'. However, the contrast occurs when the strftime() method formats the string output in a user-friendly way.
🌐
Programiz
programiz.com β€Ί python-programming β€Ί datetime β€Ί strftime
Python strftime() - datetime to string
Become a certified Python programmer. Try Programiz PRO! ... The strftime() method returns a string representing date and time using date, time or datetime object.
🌐
Analytics Vidhya
analyticsvidhya.com β€Ί home β€Ί all about python strftime() function
Python strftime() Function - Analytics Vidhya
May 27, 2025 - The `strftime` function in Python stands for β€œstring format time” and is part of the `datetime` module. It converts a `datetime` object into a string based on a specified format representing the date and time.
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί strftime-python-datetime-timestamp-string
strftime – Python DateTime Timestamp String
April 19, 2022 - In this article, we'll talk about the strftime() method provided by the datetime object. This method let us convert date and time objects in Python to their string format.
🌐
CodinGeek
codingeek.com β€Ί home β€Ί strftime function in python - python datetime module
Python strftime() - Format Date Time to String | Codingeek
August 8, 2021 - The function or method strftime() is used to get the formatted string output of the provided date, time or DateTime object.
🌐
Tutorial Gateway
tutorialgateway.org β€Ί python-strftime
Python strftime function
March 25, 2025 - Python strftime is a shorter version of string format time that allows formatting dates and times as per the requirement. As the name suggests, you can convert a given datetime object into a string representation using a specified strftime format ...
🌐
Strftime
strftime.net
Strftime
By Richard Felix and Chris Coyier. Live preview by Jake Moffatt