Standard way to express a date in a real number?

Alex Martelli aleax at aleax.it
Wed Apr 16 04:26:45 EDT 2003


sdhyok wrote:

> Tyler Eaves <tyler at cg1.org> wrote in message
> news:<bEGma.462$8c4.82 at tornadotest1.news.pas.earthlink.net>...
>> Nicola Mingotti wrote:
>> 
>> > import time
>> > t = time.time()
>> > # t is the number you asked for
>> > 
>> > If you want to know more about this look at
>> > the "time" module .
>> > 
>> > 
>> > bye.
>> 
>> The problem is that you can only represent dates from 1970 -
>> 2030-someting that way.
> 
> So, this is not the solution I am seeking.
> Better module to handle wider range of time?

In Python 2.3, module datetime may serve your needs:

>>> datetime.date(2303,4,16).toordinal()
840893
>>> datetime.date(1303,4,16).toordinal()
475651
>>>

Of course, dates before the Gregorian calendar's establishment
(which happened in different years in different nations...!)
will give somewhat arbitrary results, but apart from that you're
all right.  The result is an integer, but it's not hard to turn
it into a float if that's what you desire for some reason or other.


Alex





More information about the Python-list mailing list