Standard way to express a date in a real number?

Jeffrey.S.Whitaker at noaa.gov Jeffrey.S.Whitaker at noaa.gov
Wed Apr 16 18:41:57 EDT 2003


On Mon, 14 Apr 2003, sdhyok wrote:

> I am looking for a way to express a date in a real number
> in Python.
>
> For instance, in MatLab,
> n = datenum(2001,12,19,18,0,0) returns n = 731204.75.
>
> This kind of expression turned out to be very helpful
> when handling or storing dates.
>
> Is there any funtion for the purpose in Python (e.g. in datetime module)?
>
> Daehyok Shin
>

Daehyok:

The mx.DateTime module will do what you ask
(http://www.egenix.com/files/python/mxDateTime.html).  For example, if you
want hours since Jan 1 1900:

import mx.DateTime
year = 1900
month = 1
day = 1
hour = 0
refdate = mx.DateTime.Date(year,month,day,hour)
curdate = mx.DateTime.now()
datediff = curdate - refdate
print datediff.hours


-Jeff

 --
Jeffrey S. Whitaker         Phone : (303)497-6313
NOAA/OAR/CDC  R/CDC1        FAX   : (303)497-6449
325 Broadway                Web   : http://www.cdc.noaa.gov/~jsw
Boulder, CO, USA 80305-3328 Office: Skaggs Research Cntr 1D-124




More information about the Python-list mailing list