Getting current date alone in python

Earlier, we saw how to get the current system date and time in Python. Now we will see how to get the current date alone without the time part. There are couple of methods to get the current date. Here we see them.

Method (1)

To get the current date alone, use the today() method of date object in datetime module. Here is an example.

import datetime

today = datetime.date.today()

print("\n", today, "\n")
Getting current date alone in python

Method (2)

Another method is to use the datetime.now() method along with date() which will return the date part along from the current date and time. Here is an example.

import datetime

today = datetime.datetime.now().date()
print("\n", today, "\n")
Getting current date alone in python

Reference

Related Articles & Tools

Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.