Find Yesterday's, Today's and Tomorrow's Date Python (original) (raw)

Last Updated : 18 Nov, 2025

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.

Using datetime + timedelta

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.

Python `

from datetime import datetime, timedelta

presentday = datetime.now() yesterday = presentday - timedelta(days=1) tomorrow = presentday + timedelta(days=1)

print("Yesterday:", yesterday.strftime('%d-%m-%Y')) print("Today:", presentday.strftime('%d-%m-%Y')) print("Tomorrow:", tomorrow.strftime('%d-%m-%Y'))

`

Output

Yesterday: 13-11-2025 Today: 14-11-2025 Tomorrow: 15-11-2025

**Explanation:

Using date.today() + timedelta

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.

Python `

from datetime import date, timedelta

today = date.today() yesterday = today - timedelta(days=1) tomorrow = today + timedelta(days=1)

print("Yesterday:", yesterday.strftime('%d-%m-%Y')) print("Today:", today.strftime('%d-%m-%Y')) print("Tomorrow:", tomorrow.strftime('%d-%m-%Y'))

`

Output

Yesterday: 13-11-2025 Today: 14-11-2025 Tomorrow: 15-11-2025

**Explanation:

Using calendar Module

This method calculates yesterday/tomorrow using timedelta but uses calendar.day_name to display the day of the week like Monday, Tuesday, etc.

Python `

import calendar from datetime import date, timedelta

today = date.today() yesterday = today - timedelta(days=1) tomorrow = today + timedelta(days=1)

print("Yesterday:", calendar.day_name[yesterday.weekday()], yesterday.strftime('%d-%m-%Y')) print("Today:", calendar.day_name[today.weekday()], today.strftime('%d-%m-%Y')) print("Tomorrow:", calendar.day_name[tomorrow.weekday()], tomorrow.strftime('%d-%m-%Y'))

`

Output

Yesterday: Thursday 13-11-2025 Today: Friday 14-11-2025 Tomorrow: Saturday 15-11-2025

**Explanation:

Using Timestamp Replacement

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)

Python `

from datetime import datetime, timedelta

today = datetime.now() yesterday = datetime.fromtimestamp(today.timestamp() - 86400) tomorrow = datetime.fromtimestamp(today.timestamp() + 86400)

print("Yesterday:", yesterday.strftime('%d-%m-%Y')) print("Today:", today.strftime('%d-%m-%Y')) print("Tomorrow:", tomorrow.strftime('%d-%m-%Y'))

`

Output

Yesterday: 13-11-2025 Today: 14-11-2025 Tomorrow: 15-11-2025

**Explanation: