How to create filename containing date or time in Python
Prerequisite: DateTime module
In this article, we are going to see how to create filenames with dates or times using Python.
For this, we will use the DateTime module. First, import the module and then get the current time with datetime.now() object. Now convert it into a string and then create a file with the file object like a regular file is created using file handling concepts in Python.
Example 1: Creating text file containing date/time
Current date & time : 2023-05-11 07-21-36 File created : 2023-05-11 07-21-36.txt
Any type of file can be created in this manner if the required extension is provided correctly.
Example 2: Creating CSV file containing date/time
Current date & time : 2023-05-11 07-22-34 File created : 2023-05-11 07-22-34.csv
My Personal Notes arrow_drop_up
Please Login to comment...