Need Help comparing dates

Ben Finney bignose+hates-spam at
Fri Jun 16 03:32:45 CEST 2006

Ben Finney <bignose+hates-spam at> writes:

> colincolehour at 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:>
> Construct a date from arbitrary values with, get the
> current date with 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:


So your task now consists of:

  - get a date object of today's date using
  - 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
  - get a date object by feeding values to
  - 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

More information about the Python-list mailing list