Reputation:
I have found this
>>> import datetime
>>> today = datetime.date.today()
>>> today + datetime.timedelta(days=-today.weekday(), weeks=1)
datetime.date(2009, 10, 26)
But this returns the number of days until next Monday - how do I calculate this to the minute? I.e., not all times on Tuesday will return the same amount of minutes until Monday.
Upvotes: 1
Views: 3622
Reputation: 3443
You can calculate a timedelta between next monday and today and then print the minutes:
from datetime import datetime, timedelta
today = now = datetime.today()
today = datetime(today.year, today.month, today.day)
print (timedelta(days=7-now.weekday()) + today - now).total_seconds()/60
Upvotes: 0
Reputation: 7842
If you use the datetime.datetime.now() method instead of datetime.date.today() you can use what you already have to get the time to next monday in minutes.
Upvotes: 1
Reputation: 3240
Maybe you can use datetime.datetime likes this:
>>> today = datetime.datetime.today()
>>> today+datetime.timedelta(days=-today.weekday(), weeks=1)
datetime.datetime(2012, 1, 23, 0, 12, 2, 643512)
Is it this you are looking for??
Upvotes: 0