[Tutor] time comparison question

Brian van den Broek bvande at po-box.mcgill.ca
Fri Nov 26 20:16:40 CET 2004


Anna Ravenscroft said unto the world upon 2004-11-26 08:19:
> Brian van den Broek wrote:
> 
>> Hi all,
>>
>> I'm trying to build some Python 2.3.4 code which will determine if the 
>> actual time when it is run is after the date and time specified in 
>> some data. I want my data to be able to specify the target date/time 
>> in a various levels of detail. I.e., I want 2004-11-28 13:25, 
>> 2004-11-28, 11-28, 11-28 13:25 to all be accepted.

Hi all,

thanks to Anna, G. Rodrigues, and Liam for the replies. The code that 
was posted using datetime didn't seem so scary after all :-)

As evidence accrues, I think I am going to just have to gather myself 
together and surmount the aversion to classes and other aspects of OOP. 
At least in this case, code has shown it isn't too tricky.

One minor quibble with something Liam posted. Of struct_time objects he 
said:

> The 9 value tuple has year to microsecond, and day of the week
> contained, so you can use it if you wish.

For future googlers, my understanding is that the first 6 elements of a 
struct_time tuple are the date and time from year down to the second 
(microseconds playing no role), and the last three are weekday, day of 
year, and DST flag.

Anyway, having read the replies, it looks like my problem is solved. 
Thanks folks!

Best to all,

Brian vdB



More information about the Tutor mailing list