comparing DateTime instances

Skip Montanaro skip at pobox.com
Fri Feb 1 18:13:13 EST 2002


    >>> e = DateFrom(expected)
    >>> a = DateFrom(actual)
    >>> cmp(a, e)

Why go to the trouble of calling cmp() explicitly?  "==" seems to work for
me:

    >>> import mx.DateTime
    >>> e = mx.DateTime.DateTimeFrom("2003-01-31 14:13:13.65")
    >>> a = mx.DateTime.DateTimeFrom("2003-01-31 14:13:13.65")
    >>> e == a
    1
    >>> cmp(e,a)
    0
    >>> b = mx.DateTime.DateTimeFrom("2003-01-31 14:13:13.64")
    >>> e == b
    0
    >>> cmp(e,b)
    1
    >>> e < b
    0
    >>> e > b
    1
    >>> c = mx.DateTime.DateTimeFrom("2003-01-31 14:13:13.66")
    >>> e > c
    0
    >>> e < c
    1

See?  No need to stretch your brain out of shape after all... ;-)

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list