[python-win32] PyTime

Mark Mc Mahon mark.m.mcmahon at gmail.com
Tue May 8 14:03:01 CEST 2007


Maybe there is a better way then this suggestion...

from datetime import datetime

date = <some PyTime object>

day = int(xl.activecell.value.Format("%d"))
month = int(xl.activecell.value.Format("%m"))
year = int(xl.activecell.value.Format("%Y"))

date_as_datetime = datetime(year, month, day)

PyTime is starting to look like a wart :-) Is it a hold over from when
datetime didn't exist?


On 5/8/07, Francesco Guerrieri <f.guerrieri at gmail.com> wrote:
> hello,
> I have another newbie question. I have googled around but didn't find an
> answer.
> I have an Excel file with many dates beyond 2038, which arrive to me as a
> list of PyTime objects. From the doc I have found (
> http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/PyTime.html
>  ) it appears that an int conversion is needed to handle them. There is even
> a reference to an __int__ method which I cannot use
> >>> import pywintypes
> >>> testTime = pywintypes.Time
> >>> testTime.__int__
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
> AttributeError: 'builtin_function_or_method' object has no attribute
> '__int__'
> >>>
> In any case, int is not enough to go beyond 2038. Since I only need the day,
> month and year, and surely not the seconds :-) I would be more than happy to
> use some date object. I still haven't found how to initialize them with my
> pytime objects... can you tell me where to look for?
> thanks in advance,
> Francesco
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32

More information about the Python-win32 mailing list