Get current date using Python

27 Dec, 2019
Prerequisite: datetime module
In Python, date and time are not a data type of its own, but a module named datetime can be imported to work with the date as well as time. Datetime module comes built into Python, so there is no need to install it externally.
datetime module provide some functions to get the current date as well as time. Let’s look at them.
date.today(): today() method of date class under datetime module returns a date object which contains the value of Today’s date.Syntax: date.today()Returns: Return the current local date.Example:# Python program to get# current date    # Import date class from datetime modulefrom datetime import date    # Returns the current local datetoday = date.today()print("Today date is: ", today)Output:Today date is:  2019-12-11

Syntax: date.today()
Returns: Return the current local date.
Example:
# Python program to get# current date    # Import date class from datetime modulefrom datetime import date    # Returns the current local datetoday = date.today()print("Today date is: ", today)
Output:
Today date is:  2019-12-11

datetime.now(): Python library defines a function that can be primarily used to get current time and date. now() function Return the current local date and time, which is defined under datetime module.Syntax: datetime.now(tz)Parameters :tz : Specified time zone of which current time and date is required. (Uses Greenwich Meridian time by default.)Returns : Returns the current date and time in time format.Example:# Python program to get# current date    # Import datetime class from datetime modulefrom datetime import datetime    # returns current date and timenow = datetime.now()print("now = ", now)Output:now =  2019-12-11 10:58:37.039404
Attributes of now() :now() has different attributes, same as attributes of time such as year, month, date, hour, minute, second.Example 3: Demonstrate attributes of now().# Python3 code to demonstrate # attributes of now()     # importing datetime module for now() import datetime     # using now() to get current time current_time = datetime.datetime.now()     # Printing attributes of now(). print ("The attributes of now() are : ")     print ("Year : ", end = "") print (current_time.year)     print ("Month : ", end = "") print (current_time.month)     print ("Day : ", end = "") print (current_time.day) Output:The attributes of now() are : 
Year : 2019
Month : 12
Day : 11

Syntax: datetime.now(tz)
Parameters :tz : Specified time zone of which current time and date is required. (Uses Greenwich Meridian time by default.)
Returns : Returns the current date and time in time format.
Example:
# Python program to get# current date    # Import datetime class from datetime modulefrom datetime import datetime    # returns current date and timenow = datetime.now()print("now = ", now)
Output:
now =  2019-12-11 10:58:37.039404

Attributes of now() :now() has different attributes, same as attributes of time such as year, month, date, hour, minute, second.
Example 3: Demonstrate attributes of now().
# Python3 code to demonstrate # attributes of now()     # importing datetime module for now() import datetime     # using now() to get current time current_time = datetime.datetime.now()     # Printing attributes of now(). print ("The attributes of now() are : ")     print ("Year : ", end = "") print (current_time.year)     print ("Month : ", end = "") print (current_time.month)     print ("Day : ", end = "") print (current_time.day) 
Output:
The attributes of now() are : 
Year : 2019
Month : 12
Day : 11

Python datetime-program
Python-datetime
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Convert integer to string in Python