def datestringtoints(datestring):
    """Passed in a datestring - in the form 'yyyymmdd'
    (e.g. 20040122 being 22nd January 2004) -
    it returns an integer tuple ( yyyy, mm, dd ).
    If the datestring is of the wrong length it returns None.
    (It assumes a four figure year)."""
    if len(datestring) != 8:        # badly formed datestring
        return None
    return (int(datestring[:4]), int(datestring[4:6]), int(datestring[6:8]))