On Wed, Feb 11, 2009 at 11:21 PM, bob gailer <bgai...@gmail.com> wrote: > David wrote: >> >> I get this error with the int(time.localtime()) >> start_of_today = int(time.localtime()) >> TypeError: int() argument must be a string or a number, not >> 'time.struct_time' > > Should have been start_of_today = int(time.time())
No, that rounds to the current second, not the current day: In [5]: int(time.time()) Out[5]: 1234438429 In [6]: int(time.time()) Out[6]: 1234438432 In [7]: int(time.time()) Out[7]: 1234438433 Here are two ways to get the time at midnight in seconds since the epoch. The first one gives local midnight, the second one is UTC: import time from datetime import date Convert datetime.date.today() to seconds: In [21]: time.mktime(date.today().timetuple()) Out[21]: 1234414800.0 Round down to the nearest whole day: In [24]: now = int(time.time()) In [27]: now - (now % (60*60*24)) Out[27]: 1234396800 Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor