[python] Convert date to string

Thing you want to do

--Get the date and convert it to a string --Organized for frequent use in file names, etc.



Try converting from date to string

Execution date

--Output the current date

Execution date

# yyyymmdd
yyyymmdd = datetime.date.today().strftime('%Y%m%d')

# yyyy/mm/dd
yyyymmdd = datetime.date.today().strftime('%Y/%m/%d')

# yyyy-mm-dd
yyyymmdd = datetime.date.today().strftime('%Y-%m-%d')



Execution date and time

--Add time to execution date and time and output --Display format is yyyymmddhhmmss

Execution date

yyyymmdd_hms = datetime.date.now().strftime('%Y%m%d%H%M%S')



Date format

Use strftime () Click here for the format code [format code for strftime () and strptime ()] (https://docs.python.org/ja/3/library/datetime.html#strftime-and-strptime-format-codes)

Recommended Posts

[python] Convert date to string
[Python2] Date string-> UnixTime-> Date string
Convert Python date types to RFC822 format
Convert "number" of excel date to python datetime
Convert Windows epoch values to date with python
Convert hexadecimal string to binary
Convert numpy int64 to python int
[Python] Convert list to Pandas [Pandas]
Convert Scratch project to Python
[Python] Convert Shift_JIS to UTF-8
String date manipulation in Python
Convert python 3.x code to python 2.x
Convert timezoned date and time to Unixtime in Python2.7
How to convert / restore a string with [] in python
Convert date timezone (time difference) in Python (from string)
Python string
python> datetime> From date string (ISO format: 2015-12-09 12:40:08) to datetime type
Convert markdown to PDF in Python
Workflow to convert formula (image) to python
Convert list to DataFrame with python
Python> list> Convert double list to single list
6 ways to string objects in Python
Convert a string to an image
[Python] Convert natural numbers to ordinal numbers
How to calculate date with python
Convert decimal numbers to n-ary numbers [python]
Python> tuple> Convert double tuple to single tuple
Python: String concatenation
Convert to a string while outputting standard output with Python subprocess
Determine the date and time format in Python and convert to Unixtime
Conversion of string <-> date (date, datetime) in Python
[Python] How to convert db file to csv
Updated to Python 2.7.9
Python string format
Python date arithmetic
Convert memo at once with Python 2to3
python string slice
Convert to HSV
Convert Python> two value sequence to dictionary
[Python] How to convert a 2D list to a 1D list
How to convert Python to an exe file
[Python] Convert csv file delimiters to tab delimiters
Convert (compress) formatted JSON string to 1-line JSON
Convert psd file to png in Python
Convert Excel data to JSON with python
Convert Hiragana to Romaji with Python (Beta)
Convert from katakana to vowel kana [python]
[Python] How to invert a character string
Function to save images by date [python3]
Convert FX 1-minute data to 5-minute data with Python
python> Convert tuple to list> aList = list (pi_tuple)
Python vba to create a date string for creating a file name
Python2 string type
Convert HEIC files to PNG files with Python
Convert Chinese numerals to Arabic numerals with Python
Python string format
Python # string type
Convert from Markdown to HTML in Python
Python string inversion
Convert absolute URLs to relative URLs in Python
"Backport" to python 2