Prerequisites: datetime module
We can handle Data objects by importing the module
timedelta to work with dates.
- datetime module helps to find the present day by using the
- timedelta class from datetime module helps to find the previous day date and next day date.
Syntax for timedelta:
class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
timedelta class is used because manipulating the date directly with increment and decrement will lead to a false Date. For example, if the present date is 31th of December, incrementing the date directly will only lead to the 32nd of December which is false. If we want to manipulate the Date directly first we have check day month and year combined and them increment accordingly. But, all this mess can be controlled by using timedelta class.
Syntax to find a present-day date:
Returns: A datetime object containing the current local date and time.
Syntax to find a previous-day and next-day date:
previous-day = datetime.now()-timedelta(1)
next-day = datetime.now()+timedelta(1)
Yesterday = 10-12-2019 Today = 11-12-2019 Tomorrow = 12-12-2019
- How to print date starting from the given date for n number of days using Pandas?
- Python program to find day of the week for a given date
- Python | Working with date and time using Pandas
- Python | Swap Name and Date using Group Capturing in Regex
- Get Current Date and Time using Python
- Display date and time in videos using OpenCV - Python
- Python Tweepy – Getting the date and time when a tweet was tweeted
- Get month and Year from Date in Pandas - Python
- Time Functions in Python | Set-2 (Date Manipulations)
- Python | Pandas Timestamp.date
- Python | Pandas DatetimeIndex.date
- Python | Pandas Series.dt.date
- Python | Sort given list of dictionaries by date
- Python | Create an empty text file with current date as its name
- Get Yesterday's date using Python
- Get current date using Python
- Convert date string to timestamp in Python
- Python IMDbPY – Getting birth date of person
- Get Month from date in Pandas - Python
- Extract week number from date in Pandas-Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.