Datetime class
This method is similar to the date method but this is an upgraded version of the date object which will get you both the date and time from your local system. Let’s write the same program, which we wrote for the date object but this time to calculate the remaining days with time.
Example: Program to count remaining days
Python3
from datetime import datetime # By using now(), We will get both current # date and time Storing current time and # date into a variable today = datetime.now() # Storing the date and time you want to calculate # In this you have to give the time as the input graduation_day = datetime( 2023 , 8 , 11 , 0 , 0 , 0 ) # finding the difference from days_left = abs (graduation_day - today) # Displaying the no.of.days left with time print (f "Time left till the graduation: {days_left}" ) |
Output:
Time left till the graduation: 681 days, 22:12:03.851113
Working With Dates in Python
In this article, we will discuss how to work with dates using python.
Python makes dealing with dates and time very easy, all we have to do is import a module named DateTime that comes along with python. It is a more efficient way to work with date without the need of being explicitly programmed. By using this module, You will get the time and date from the timezone that your local computer is present. This module just gets the date and time from the host computer ( Which in this case, it is your computer from which the program is executed ).