Search code examples
pythonpython-datetime

Is there an object that compares smaller than any valid datetime.datetime(...)?


Is there a MIN constant for datetime?

I need it to represent the expiration date of a resource, and I want to have a datetime that represents "always expires" as default value (instead of None so I can use the same expiration comparison no matter what).

So right now I'm using datetime.datetime(datetime.MINYEAR,1,1,0,0,tzusc()) as my MIN datetime but I wonder if there is some other way to represents "the lowest possible time" (even if it's not a datetime).


Solution

  • You can try - datetime.datetime.min . According to documentation -

    datetime.min

    The earliest representable datetime, datetime(MINYEAR, 1, 1, tzinfo=None).