Suggestion:yesterday() in datetime()

I suggest add datetime.yesterday() like, such as datetime.yesterday().date(), even it is easy to code using timedelta(days=1), but it’s easy to understand while analysis daily data backward.

Just as a note: If this would be added, it should be added as date.yesterday(), similar to (And for completeness sake, date.tomorrow() would makes sense as well.)


Thanks for your addition, I thought of this after Posting, and indeed Date() is more appropriate (my own project only calls datetime() because it involves hour and minute data, so I am lazy to ‘import date’ when I occasionally need the previous day’s date data, So I used ‘’ instead)

Somewhat related discussion: makes no sense and should be removed · Issue #86070 · python/cpython · GitHub

Even if this were added as date.yesterday(), we’d still inevitably get a datetime.yesterday() since datetime is a subclass of date.

If accepted, I imagine this won’t be available until 3.13 at the earliest… yesterday seems so far away.


As I known, date is subclass of datetime…

U r right, Thanks

Subclass relationships:


  • timedelta
  • tzinfo
    • timezone
  • time
  • date
    • datetime

I think yesterday(), tomorrow() and the like are too niche to add to the datetime module. And they’re trivial to implement, and hard to get wrong.


Maybe we could implement date + int and date - int. Then we could write - 1  # yesterday + 2  # the day after tomorrow + 7  # same day next week

A lot easier than + date.timedelta(days=2)

It’s easier but a heck of a lot less specific and obvious. Units are good!


Also a lot less precise and possibly surprising. Why should the int mean days?


If you’re just looking for a nicer syntax than timedelta then you can do:

days = timedelta(days=1)

tomorrow = + 1*days
next_week = + 7*days

Like Oscar pointed out, a simple recipe is to just define DAY as a constant.

>>> from datetime import date, timedelta
>>> DAY = timedelta(days=1)
>>>, 12, 20)
>>> - DAY, 12, 19)
>>> - 2 * DAY, 12, 18)
>>> + 31 * DAY, 1, 20)

You could even define a custom function or lambda to take make a tomorrow callable:

>>> tomorrow = lambda: + DAY
>>> tomorrow(), 12, 21)

You could similarly define a WEEK as so:

>>> WEEK = timedelta(days=7)
>>>, 12, 20)
>>> + WEEK, 12, 27)

You wouldn’t want to do any more than a week, as months and years change based on the weirdness of the calendar.


day is the atomic unit of a date


Personally, I just suggest it is easy to understand & define. specially using in loop. such as below:

for …(date)…
date = date.yesterday()


if date_from_db == date.yesterday() :

if date_from_db ==

if date_from_db == date.tomorrow():


That’s actually such a neat trick that I wish that datetime would add those constants. While it’s easy to define them yourself, that would great for discoverability and ease of use.

The problem with adding it to the stdlib is that you really have to start looking at corner cases, such as how to interact with Daylight Savings Time. There’s every chance that corner cases might be missed if it were added to the stdlib, and then we’d be stuck with the implementation and still have to work around it with custom code or external libraries, which leaves us in no better spot than today.

See: python - How to subtract a day from a date? - Stack Overflow