I’m using the following expression to get the time of 1:30 AM tomorrow.
import datetime
t = datetime.date.today()
datetime.datetime.combine(t, datetime.time.min) + datetime.timedelta(hours=1, days=1, minutes=30)
Is there a better way to do it?
>Solution :
Your way of writing is totally alright, another way of achieving same task is:
from datetime import datetime
now = datetime.now()
print(datetime(year = now.year, month = now.month,
day = now.day + 1, hour = 1, minute = 30))
Output:
2021-11-28 01:30:00
Just figured out that the way of writing as above will not work for the last day of the month, then it is better to do as following:
import datetime
now = datetime.datetime.now()
print(datetime.datetime(year = now.year, month = now.month, day = now.day)
+ datetime.timedelta(days = 1, hours = 1, minutes = 30))
Output:
2021-11-28 01:30:00