Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Python | Create an empty text file with current date as its name

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will learn how to create a text file names as the current date in it. For this, we can use now() method of datetime module.

The datetime module supplies classes for manipulating dates and times in both simple and complex ways. While date and time arithmetic is supported, the focus of the implementation is on efficient attribute extraction for output formatting and manipulation.

Let’s see a code example and try to understand it better.

# Python script to create an empty file
# with current date as name.
# importing datetime module
import datetime
# to get 
# current date as filename.
filename =
# create empty file
def create_file():
    # Function creates an empty file
    # %d - date, %B - month, %Y - Year
    with open(filename.strftime("%d %B %Y")+".txt", "w") as file:
# Driver Code


01 August 2019.txt
My Personal Notes arrow_drop_up
Last Updated : 02 Aug, 2019
Like Article
Save Article
Similar Reads
Related Tutorials