To print the current date, we can utilize the datetime module. Dates are objects, like anything in Python. Datetime has several subclasses, which can be confusing at first.

Related course:
Complete Python Bootcamp: Go from zero to hero in Python

Date Example

We can use its method strftime() to change the format.
To show the current date (today):

This will show the date in the format


If you want another format, use the method strftime():

This will output


Get current time in Python

You can get the current time like this:

To get the date and time, use:

Format codes

When using the method strftime() we can specify the type of date format we want to show.
So which format codes do we have?

Previous Post

Leave a Reply