VOOZH about

URL: https://www.geeksforgeeks.org/python/python-find-yesterdays-todays-and-tomorrows-date/

⇱ Find Yesterday's, Today's and Tomorrow's Date - Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find Yesterday's, Today's and Tomorrow's Date - Python

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.


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

Explanation:

  • presentday = datetime.now() retrieves the current local date and time.
  • timedelta(days=1) creates a time difference of one day.
  • presentday - timedelta(1) gives yesterday and presentday + timedelta(1) gives tomorrow.
  • strftime('%d-%m-%Y') formats the date into a readable string.

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.


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

Explanation:

  • date.today() gives only the current date (no time).
  • timedelta(days=1) adds/subtracts a day cleanly.
  • .strftime() converts the date into dd-mm-yyyy format.

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.


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

Explanation:

  • calendar.day_name[...] returns day name like "Thursday".
  • .weekday() returns day index (0=Monday, 6=Sunday).

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)


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

Explanation:

  • today.timestamp() converts today's date to seconds.
  • - 86400 subtracts 24 hours to get yesterday.
  • + 86400 adds 24 hours to get tomorrow.
  • datetime.fromtimestamp() converts the timestamp back to a date.
Comment