You can use strftime:
>>> from datetime import datetime >>> datetime.today().strftime('%Y-%m-%d') '2021-01-26'
Additionally, for anyone also looking for a zero-padded Hour, Minute, and Second at the end: (Comment by Gabriel Staples)
>>> datetime.today().strftime('%Y-%m-%d-%H:%M:%S') '2021-01-26-16:50:03'
Related Posts:
- Datetime strptime in python
- How to get the current time in Python
- Creating a range of dates in Python
- Converting string into datetime
- Converting string into datetime
- Difference between UTC and GMT
- Python datetime to string without microsecond component
- How do I get the current date and time in PHP?
- Convenient way to deal with ValueError: cannot reindex from a duplicate axis
- Converting string into datetime
- How to get current timestamp in string format in Java? “yyyy.MM.dd.HH.mm.ss”
- How to get the current date/time in Java [duplicate]
- What’s the difference between ISO 8601 and RFC 3339 Date Formats?
- Convert DataFrame column type from string to datetime, dd/mm/yyyy format
- How to get the current date/time in Java
- Can’t compare naive and aware datetime.now() <= challenge.datetime_end
- How to compare two dates?
- NOW() function in PHP
- Can only use .dt accessor with datetimelike values
- Converting between datetime and Pandas Timestamp objects
- How do I do a Date comparison in Javascript?
- How to convert string to datetime format in pandas python?
- Convert datetime to Unix timestamp and convert it back in python
- Convert date to datetime in Python
- Converting between java.time.LocalDateTime and java.util.Date
- How do I get the day of week given a date?
- Parse date string and change format
- Setting the Timezone for PHP in the php.ini file
- datetime to string with series in pandas
- Convert Pandas Column to DateTime
- Adding hours to JavaScript Date object?
- How do I find the time difference between two datetime objects in python?
- How do I calculate the date six months from the current date using the datetime Python module?
- Get current time in milliseconds in Python?
- How can I convert a datetime object to milliseconds since epoch (unix time) in Python?
- error: command ‘gcc’ failed with exit status 1 while installing eventlet
- How do I merge dictionaries together in Python?
- Python foreach equivalent
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Limiting floats to two decimal points
- Use a.any() or a.all()
- What is the difference between Spyder and Jupyter?
- What is the maximum recursion depth in Python, and how to increase it?
- subprocess.check_output return code
- Unzip all zipped files in a folder to that same folder using Python 2.7.5
- How to round a number to significant figures in Python
- Why Python 3.6.1 throws AttributeError: module ‘enum’ has no attribute ‘IntFlag’?
- Python subprocess.Popen “OSError: [Errno 12] Cannot allocate memory”
- Creating 2D dictionary in Python
- Python: slicing a multi-dimensional array
- Python: pandas merge multiple dataframes
- Shuffle an array with python, randomize array item order with python
- Which Python memory profiler is recommended? [closed]
- How to count the NaN values in a column in pandas DataFrame
- How to install multiple python packages at once using pip
- Implement touch using Python?
- Running Selenium with Headless Chrome Webdriver
- boto3 client NoRegionError: You must specify a region error only sometimes
- Converting Dictionary to List?
- pip3: command not found
- How to get keyboard input in pygame?
- Series Summation using for loop in python
- How to iterate through two lists in parallel?
- Make list of arrays in python
- In Python, what is `sys.maxsize`?
- Pyspark: Exception: Java gateway process exited before sending the driver its port number
- Converting from a string to boolean in Python?
- Import Error: No module named numpy Anaconda
- How to remove \n from a list element?
- Python Weighted Random [duplicate]
- Is it possible to decompile a compiled .pyc file into a .py file?
- Writing string to a file on a new line every time
- Creating lowpass filter in SciPy – understanding methods and units
- Python 2: AttributeError: ‘list’ object has no attribute ‘strip’
- Get Confusion Matrix From a Keras Multiclass Model
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- Insert a row to pandas dataframe
- Anaconda Installed but Cannot Launch Navigator
- How to save a Seaborn plot into a file
- How to get the unit vector from a numpy array
- Subtract two columns in dataframe
- Inverse of Tan in python (tan-1)
- How do I disable “missing docstring” warnings at a file-level in Pylint?
- How to convert column with dtype as object to string in Pandas Dataframe
- When I use matplotlib in jupyter notebook,it always raise ” matplotlib is currently using a non-GUI backend” error?
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- IndexError: index 2 is out of bounds for axis 0 with size 2
- ‘if’ statement in jinja2 template
- Python name ‘os’ is not defined
- Python can’t find module NLTK
- Python CSV Error: sequence expected
- How to set NotebookApp.iopub_data_rate_limit and others NotebookApp settings in JupyterHub?
- Base language of Python
- How do operator.itemgetter() and sort() work?
- python ValueError: invalid literal for float()
- How to use Stanford Parser in NLTK using Python
- How to convert .sav file into csv file
- Anaconda “failed to create process”
- OpenMP and Python
- PHP: date function to get month of the current date