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.
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")
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")
- More about datetime.date object at Python docs.