Class 12: Date and Time Inbuilt Functions

Introduction:
Python supports yyyy-mm-dd format of displaying the date. The datetime module in python handles the extraction and formatting of date and time variables. calendar date values are represented and assoicated with date class.

date class:
Following are the attributes under date class:

today():
This method is used to create a date representing today’s date or the current system date.
Example:

import datetime
t_date=datetime.date.today()
print("today's date is ",t_date)
#Output
today's date is  2020-07-10
>>> 

year():
This attribute returns and display year from the datetime object.
example:

import datetime
t_date=datetime.date.today()
print("year is ",t_date.year)
#Output
year is  2020
>>> 

month():
This attribute returns and display month from the datetime object.
example:

import datetime
t_date=datetime.date.today()
print("Month is ",t_date.month)
#Output
Month is  7
>>> 

day():
This attribute returns and display day from the datetime object.
example:

import datetime
t_date=datetime.date.today()
print("Day is ",t_date.day)
# Output
Day is  10
>>> 

time class:
Following are the attributes under this class:

now():
This method returns the current date and time using datetime library/module.
Example:

import datetime
t_date=datetime.datetime.now()
print("Today is ",t_date)
Output:
Today is  2020-07-10 14:40:14.483724
>>> 

hour():
This attribute returns and display hours from the datetime object.
example:

import datetime
t_date=datetime.datetime.now()
print("hours are ",t_date.hour)
#Output:
hours are  14
>>> 

minute():
This attribute returns and display minutes from the datetime object.
example:

import datetime
t_date=datetime.datetime.now()
print("Minutes are ",t_date.minute)
#Output:
Minutes are  44
>>> 

second():
This attribute returns and display seconds from the datetime object.
example:

import datetime
t_date=datetime.datetime.now()
print("Seconds are ",t_date.second)
#Output
Seconds are  17
>>>

Python String Inbuilt Function       Python Math Inbuilt Function       Python Data and Time Inbuilt Functions       Python Random Module Functions