Gurus,
I'm trying to write a fairly simple script that finds the number of hours /
minutes / seconds between now and the next Friday at 1:30AM.
I have a few little chunks of code but I can't seem to get everything to piece
together nicely.
import datetime,time
now = datetime.datetime.now()
i = 0
dayOfWeek = datetime.datetime.now().strftime( '%a' )
while dayOfWeek != 'Fri':
delta = datetime.timedelta( days = i )
tom = ( now + delta ).strftime( '%a' )
if tom != 'Fri':
i = i + 1
else:
print i
print tom
break
So with this code I can determine the number of days until the next Friday (if
it's not Friday already).
The problem I'm having, however, is with finding the number of minutes until
1:30AM on Friday.
nextFridayDay = int( now.strftime( '%d' ) ) + 1
nextFridayMonth = int( now.strftime( '%m' ) )
nextFridayYear = int( now.strftime( '%Y' ) )
nextRun = datetime.datetime( nextFridayYear , nextFridayMonth , nextFridayDay ,
1 , 30 , 0 )
What I gather is that I should be able to numerically manipulate two datetime
objects, as seen below:
In [227]: nextRun - now
Out[227]: datetime.timedelta(0, 46155, 51589)
The result, however, doesn't make sense. Take a look...
In [231]: d = nextRun - now
In [232]: d.seconds
Out[232]: 46155
In [233]: d.days
Out[233]: 0
Thoughts on what I may be doing wrong? Am I going about this the whole wrong
way? Should I be using something different to calculate the number of minutes
between now and the next Friday at 1:30AM?
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor