Use strftime:

>>> from datetime import datetime
>>> datetime.today().strftime('%Y-%m-%d')
'2021-01-26'

To also include a zero-padded Hour:Minute:Second at the end:

>>> datetime.today().strftime('%Y-%m-%d %H:%M:%S')
'2021-01-26 16:50:03'

To get the UTC date and time:

>>> datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
'2021-01-27 00:50:03'
Answer from diegueus9 on Stack Overflow
🌐
PythonHow
pythonhow.com › how › get-todays-date-and-convert-to-string
Here is how to get today's date and convert to string in Python
The returned date has year, month, and day attributes. strftime("%Y-%m-%d"): This method formats the date object as a string. The %Y is replaced by the full year with century, %m by the zero-padded month, and %d by the zero-padded day of the month. Using strftime, you can format dates in virtually ...
Discussions

datetime - How do I get a string format of the current date time, in python? - Stack Overflow
For example, on July 5, 2010, I would like to calculate the string July 5, 2010 How should this be done? More on stackoverflow.com
🌐 stackoverflow.com
How Do I make Python Return today's date in YYMMDD format?

The date.strftime() method can print the date in any format you require. You just need to create the format string and the codes in that string are documented here. In your case, use "%y%m%d". I would strongly recommend using 4 digit years if at all possible, e, "%Y%m%d".

More on reddit.com
🌐 r/learnpython
4
5
May 29, 2018
How do I turn a python datetime into a string, with readable format date? - Stack Overflow
0 Converting Between DateTime Objects & Strings in Python · 1164 Converting Unix timestamp string to readable date ... Can military infiltration of humanitarian organizations violate international law and war conventions? Bingo Games slang expression for overlooking a win? More on stackoverflow.com
🌐 stackoverflow.com
Help with adding date to a string
Sorry, new to Python and programming as a whole. I'm getting a syntax error on this bit I'm working on and I can't figure out why. Import pyautogui Import datetime pyautogui.write('Filename' + %m%d%y + '.txt') It's giving me a syntax error on the date part. I want the file name to be "FilenameMMDDYY.txt" Share ... You need to call a datetime function to get the current date, convert it to a string ... More on reddit.com
🌐 r/learnpython
5
1
November 23, 2020
🌐
W3Schools
w3schools.com › python › python_datetime.asp
Python Datetime
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects.
🌐
nixCraft
cyberciti.biz › nixcraft › howto › python › python get today’s current date and time
Python Get Today's Current Date and Time - nixCraft
August 6, 2024 - This line tells python script to create a date object for the current date and stores it in the variable named today. fdate = date.today().strftime('%d/%m/%Y') : Format the date as a string as dd/mm/YYYY format. print("Today's current date is ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › get-current-date-using-python
Get current date using Python - GeeksforGeeks
July 12, 2025 - # Import date class from datetime module from datetime import date # Returns the current local date today = date.today() print("Today date is: ", today) ... Python library defines a function that can be primarily used to get the current time ...
🌐
Programiz
programiz.com › python-programming › datetime › current-datetime
How to get current date and time in Python? (With Examples)
Become a certified Python programmer. Try Programiz PRO! ... There are a number of ways we can take to get the current date. We will use the date class of the datetime module to accomplish this task. from datetime import date today = date.today() print("Today's date:", today)
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
Return a date corresponding to a date_string given in any valid ISO 8601 format, with the following exceptions: Reduced precision dates are not currently supported (YYYY-MM, YYYY). Extended date representations are not currently supported (±YYYYYY-MM-DD). Ordinal dates are not currently supported (YYYY-OOO). ... >>> import datetime as dt >>> dt.date.fromisoformat('2019-12-04') datetime.date(2019, 12, 4) >>> dt.date.fromisoformat('20191204') datetime.date(2019, 12, 4) >>> dt.date.fromisoformat('2021-W01-1') datetime.date(2021, 1, 4)
🌐
Reddit
reddit.com › r/learnpython › how do i make python return today's date in yymmdd format?
r/learnpython on Reddit: How Do I make Python Return today's date in YYMMDD format?
May 29, 2018 -

How Do I make Python Return today's date in YYMMDD format? I've tried this:

import datetime

today = datetime.date.today()

print today

but it just returns this : 2020-04-06 which is the correct date. However, I need the date to be 200406 (YYMMDD)(no spaces, slashes, or anything). Is there any way of doing this?

Thank you so much if you can help!

🌐
W3docs
w3docs.com › python
Getting today's date in YYYY-MM-DD in Python?
This code imports the datetime module, gets the current date and time using datetime.now(), and then formats the date as a string using the strftime() method. The %Y format code is used to display the year with century as a decimal number, %m ...
🌐
Educative
educative.io › answers › what-is-the-datetime-datetoday-function-in-python
What is the datetime date.today() function in Python?
Line 5: We printed the today variable on the console. Line 7-8: We can print date on the console in different formats with the date.strftime() method. It converts the given date objects to a string according to the specified format as an argument.
🌐
iO Flood
ioflood.com › blog › python-get-current-date
Python Get Current Date | date.today() And More
February 7, 2024 - Python’s strftime function allows you to format the date and time in many different ways. The strftime function stands for ‘string format time’. It converts a date to a string and allows you to specify the format.
🌐
Squash
squash.io › how-to-get-todays-date-in-yyyy-mm-dd-format-in-python
How to Get Today's Date in YYYY MM DD Format in Python
November 2, 2023 - In this example, we first use strftime() to get the current date as a string in the format "YYYY-MM-DD". Then, we use strptime() to parse the date string and convert it to a datetime object.
🌐
Programiz
programiz.com › python-programming › datetime › strftime
Python strftime() - datetime to string
It's because the object of datetime class can access strftime() method. The datetime object containing current date and time is stored in now variable. The strftime() method can be used to create formatted strings. The string you pass to the strftime() method may contain more than one format ...
🌐
Mimo
mimo.org › glossary › python › datetime
Python datetime Module: Working with Dates, Times, and Formatting
from datetime import datetime now = datetime.now() # Format the date into "Weekday, Month Day, Year" formatted_string = now.strftime("%A, %B %d, %Y") print(formatted_string) # Example Output: 'Monday, June 15, 2025' The format codes (%Y, %m, %d, etc.) define how the date and time components are represented. To work with dates and times in Python, you need to import the datetime module. The Python date and time module provides several classes for formatting and manipulating date and time values.
🌐
w3resource
w3resource.com › python-exercises › python-basic-exercise-3.php
Python: Print current time and date - w3resource
May 17, 2025 - The fourth line print (now.strftime("%Y-%m-%d %H:%M:%S")) uses the strftime() method of the datetime object to format the date and time as a string in the format "YYYY-MM-DD HH:MM:SS" and prints it to the console.
🌐
Scaler
scaler.com › home › topics › python program to get current date in list
Python Program to Get Current Date in List - Scaler Topics
May 4, 2023 - The format string we used was "%a, %d %B %Y". This formats the date as the day of the week, day of the month, month, and year. In this article, we have looked at how to get the current date in Python in different ways.
🌐
Reddit
reddit.com › r/learnpython › help with adding date to a string
r/learnpython on Reddit: Help with adding date to a string
November 23, 2020 - now = datetime.datetime.now() today = datetime.datetime.strftime(now, "%m%d%y") ... Advice on which IDE to use for my relatively basic data analysis purposes. ... Invalid set index 'password' (on base: 'Node(Global.gd)') with value of type 'string'.