Ben Finney <[EMAIL PROTECTED]> writes: > [EMAIL PROTECTED] writes: > > I am new to Python and am working on my first program. I am trying > > to compare a date I found on a website to todays date. The problem I > > have is the website only shows 3 letter month name and the date. > > Example: Jun 15 > > The 'datetime' module in the standard library will do the job of > creating date objects that can be compared. > > <URL:http://docs.python.org/lib/module-datetime> > > Construct a date from arbitrary values with datetime.date(), get the > current date with datetime.date.today(). The objects returned by those > functions can be compared directly. > > As for how to get from a string representation to a date object, > you're now talking about parsing strings to extract date/time > information. This isn't provided in the standard library
As soon as I sent this, I remembered that the standard library *does* provide datetime parsing: <URL:http://docs.python.org/lib/module-time#l2h-1956> So your task now consists of: - get a date object of today's date using datetime.date.today() - define a format for parsing a string date - get a struct_time object from time.strptime() feeding it the string and the format - make any assumptions about missing pieces of the date (e.g. the year) - get a date object by feeding values to datetime.date() - compare the two date objects -- \ "Hey Homer! You're late for English!" "Pff! English, who needs | `\ that? I'm never going to England!" -- Barney & Homer, _The | _o__) Simpsons_ | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list