Cleanest and most Pythonic way to get tomorrow's date?


What is the cleanest and most Pythonic way to get tomorrow’s date? There must be a better way than to add one to the day, handle days at the end of the month, etc.

Asked By: linkmaster03


Answers: + datetime.timedelta(days=1) should do the trick

Answered By: Kamil Szot

timedelta can handle adding days, seconds, microseconds, milliseconds, minutes, hours, or weeks.

>>> import datetime
>>> today =
>>> today, 10, 1)
>>> today + datetime.timedelta(days=1), 10, 2)
>>>,10,31) + datetime.timedelta(hours=24), 11, 1)

As asked in a comment, leap days pose no problem:

>>>, 2, 28) + datetime.timedelta(days=1), 2, 29)
>>>, 2, 28) + datetime.timedelta(days=2), 3, 1)
>>>, 2, 28) + datetime.timedelta(days=1), 3, 1)
Answered By: Mark Rushakoff

No handling of leap seconds tho:

>>> from datetime import datetime, timedelta
>>> dt = datetime(2008,12,31,23,59,59)
>>> str(dt)
'2008-12-31 23:59:59'
>>> # leap second was added at the end of 2008, 
>>> # adding one second should create a datetime
>>> # of '2008-12-31 23:59:60'
>>> str(dt+timedelta(0,1))
'2009-01-01 00:00:00'
>>> str(dt+timedelta(0,2))
'2009-01-01 00:00:01'


EDIT – @Mark: The docs say “yes”, but the code says “not so much”:

>>> time.strptime("2008-12-31 23:59:60","%Y-%m-%d %H:%M:%S")
(2008, 12, 31, 23, 59, 60, 2, 366, -1)
>>> time.mktime(time.strptime("2008-12-31 23:59:60","%Y-%m-%d %H:%M:%S"))
>>> time.gmtime(time.mktime(time.strptime("2008-12-31 23:59:60","%Y-%m-%d %H:%M:%S")))
(2009, 1, 1, 6, 0, 0, 3, 1, 0)
>>> time.localtime(time.mktime(time.strptime("2008-12-31 23:59:60","%Y-%m-%d %H:%M:%S")))
(2009, 1, 1, 0, 0, 0, 3, 1, 0)

I would think that gmtime or localtime would take the value returned by mktime and given me back the original tuple, with 60 as the number of seconds. And this test shows that these leap seconds can just fade away…

>>> a = time.mktime(time.strptime("2008-12-31 23:59:60","%Y-%m-%d %H:%M:%S"))
>>> b = time.mktime(time.strptime("2009-01-01 00:00:00","%Y-%m-%d %H:%M:%S"))
>>> a,b
(1230789600.0, 1230789600.0)
>>> b-a
Answered By: PaulMcG

Even the basic time module can handle this:

import time
time.localtime(time.time() + 24*3600)
Answered By: u0b34a0f6ae

For people who are dealing with servers Time Stamp

To get yesterday Time Stamp:

yesterdaytimestamp = + datetime.timedelta(days=-1)

To get Today Time Stamp:

currenttimestamp =

To get Tomorrow Time Stamp:

tomorrowtimestamp = + datetime.timedelta(days=1)

To print:

print('n Yesterday TimeStamp is : ', yesterdaytimestamp.timestamp(), 
    'n Today TimeStamp is :', currenttimestamp, 
    'n Tomorrow TimeStamp is: ', tomorrowtimestamp.timestamp())

The output:

Yesterday TimeStamp is :  1632842904.110993 
Today TimeStamp is       :  1632929304.111022 
Tomorrow TimeStamp is    :  1633015704.11103
Answered By: Mr Dream

There’s nothing at all wrong with using today() as shown in the selected answer if that is the extent of your needs. + datetime.timedelta(days=1)

Alternatively, if you or someone else working with your code might need more precision in handling tomorrow’s date, consider using instead of today(). This will certainly allow for simpler, more readable code: + datetime.timedelta(days=1)

This returns something like:

datetime.datetime(2022, 2, 17, 19, 50, 19, 984925)

The advantage is that you can now work with datetime attributes in a concise, human readable way:

class datetime.datetime

A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo.


You can easily convert this to a date object withdate():

import datetime
tomorrow = + datetime.timedelta(days=1)
print(f"Tomorrow's date is {}") is easy to use and it is very clear to anyone reading your code that it is returning the date for tomorrow. The output for the above looks like so:
Tomorrow's date is 2022-02-17

If later in your code you only need the date number for the day, you can now use

print(f"Tomorrow is the {}rd")

Which will return something like:
Tomorrow is the 17rd

That’s a silly example, but you can see how having access to these attributes can be useful and keep your code readable as well. It can be easily understood that returns the day number.

Need to work with the exact time tomorrow’s date begins? You can now replace the hours, minutes, seconds, and microseconds:

# Replace all attributes except day with 0.
midnight = tomorrow.replace(
# Print midnight as the beginning of tomorrow's date.

Reading the above code, it should be apparent which attributes of tomorrow are being replaced. When midnight is printed, it will output:
2022-02-17 00:00:00

Need to know the time left until tomorrow’s date? Now something like that is possible, simple, and readable:

print(f"{midnight -}")

The output is the time to the microsecond that tomorrow’s date begins:

There are many ways people might wish to handle tomorrow’s date. By ensuring these attributes are available from the beginning, you can write more readable code and avoid unnecessary work later.

Answered By: iyrin

For the case you only want to calculate the timestamp

import time
tomorrow = (int(time.time() / 86400) + 1) * 86400
Answered By: MattPatrik
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.