views:

124

answers:

3

Hi,

I have written a function comp(time1, time2) which will return true when time1 is lesser than time2. I have a scenario where time1 should always be lesser than time2. I need time1 to have the least possible value(date). How to find this time and how to form the corresponding object.

+7  A: 

In python, the datetime object exports the following constants

datetime.MINYEAR
The smallest year number allowed in a date or datetime object. MINYEAR is 1.

datetime.MAXYEAR
The largest year number allowed in a date or datetime object. MAXYEAR is 9999.

http://docs.python.org/library/datetime.html

Silfverstrom
+2  A: 

If you're using standard issue unix timestamp values then the earliest representable moment of time is back in 1970:

>>> import time
>>> time.gmtime(0)
(1970, 1, 1, 0, 0, 0, 3, 1, 0)
korona
Actually no, for time.gmtime() it's -67768040609740804 for the 1.st january of the year -2147481748.
Ants Aasma
+1  A: 

Certain functions in the datetime module obey datetime.MINYEAR and datetime.MAXYEAR and will raise a ValueException for dates outside that range. These are assigned to 1 and 9999, respectively.

The calender module relies heavily on the datetime module, but in general, observes the “proleptic Gregorian”, which extends indefinately in both directions.

the time module similarly places no particular restrictions on year elements in time tuple values, and calculates times and dates using only seconds since the epoch.


That being said, you cannot reliably process dates before about February 12, 1582, when the Gregorian calender was adopted. Before that day, dates were computed using a variety of location dependent calenders, for which there is no support in standard python.

TokenMacGuy