![]() |
VOOZH | about |
Given a current date, the task is to print yesterday’s, today’s, and tomorrow’s date. For example:
If today = 14-11-2025
Yesterday = 13-11-2025
Tomorrow = 15-11-2025
Let’s explore different methods to compute and print these dates in Python.
This method uses datetime.now() to get today’s date, then adds or subtracts a timedelta of 1 day to derive yesterday and tomorrow. It automatically handles edge cases like month-end and leap years.
Yesterday: 13-11-2025 Today: 14-11-2025 Tomorrow: 15-11-2025
Explanation:
This version uses the date class instead of datetime. It works directly with only the date part, making it simpler when time is not needed.
Yesterday: 13-11-2025 Today: 14-11-2025 Tomorrow: 15-11-2025
Explanation:
This method calculates yesterday/tomorrow using timedelta but uses calendar.day_name to display the day of the week like Monday, Tuesday, etc.
Yesterday: Thursday 13-11-2025 Today: Friday 14-11-2025 Tomorrow: Saturday 15-11-2025
Explanation:
This method converts today into a timestamp, manually adjusts the timestamp by adding or subtracting 86400 seconds, then converts it back into a date. It works but is less intuitive. (86400 seconds = 24 hours)
Yesterday: 13-11-2025 Today: 14-11-2025 Tomorrow: 15-11-2025
Explanation: