Python Date:
in python data type are not created but we can import a module with dates as date objects in that sequence.Import datetime module and display current date:
import datetime x = datetime.datetime.now()
print(x)
2018-07-06 2:44:07.670539
The date having year, month, day, hour, minute, second, microsecond.
The datetime module has many methods to return information about the date object. Return the year and name of weekday:
import datetime x = datetime.datetime.now()
print(x.year)
print(x.strftime("%A"))
Creating Date Objects :
you can use the datetime() class (constructor) of the datetime module for creating a date. The datetime() class requires three parameters to create a date: year, month, day.
Create a date object:
import datetime x = datetime.datetime(2020,6,20)
print(x)
The strftime() Method:
The datetime object has a method for formatting date objects into readable strings.
Display the name of the month:
import datetime x = datetime.datetime(2018, 6, 1)
print(x.strftime("%B"))
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Python Date: in python data type are not created but we can import a module with dates as date objects in that sequence.Import datetime module and display current date:
The date having year, month, day, hour, minute, second, microsecond. The datetime module has many methods to return information about the date object. Return the year and name of weekday:
Creating Date Objects :
you can use the datetime() class (constructor) of the datetime module for creating a date. The datetime() class requires three parameters to create a date: year, month, day.
Create a date object:
The strftime() Method:
The datetime object has a method for formatting date objects into readable strings.
Display the name of the month: