[python-win32] Python Dates and Windows dates

Larry Bates lbates at syscononline.com
Thu Jan 15 08:55:14 EST 2004


Here is some code from a project I did last year that seems
to work.  Note: You will need to get mx.DateTime from
http://www.lemburg.com/files/python/mxDateTime.html
(if you don't already have this excellent tool involved).

FYI, Larry


from mx.DateTime import DateTime
from mx.DateTime import DateTimeFromCOMDate
import time


def strDateFromCOMDate(comdate, format):
    _trace=0
    _debug=0
    if _trace: print "Entering strDateFromCOMDate, comdate=%f, format=%s" %
(comdate, format)
    #
    # Creates string date representation from COMDate
    # Format is a string defining what format you want the Date returned
    # in.  See time.strftime format specifications in Python manuals for
    # description of format options (e.g. "%m/%d/%y" = MM/DD/YY).
    #
    t=DateTimeFromCOMDate(comdate)
    rdate=time.strftime(format, t.tuple())
    if _trace: print "Leaving strDateFromCOMDate, date=%s" % rdate
    return rdate


def COMDateFromstrDate(strdate):
    _trace=0
    _debug=0
    if _trace: print "Entering COMDateFromstrDate, strdate=%s" % strdate
    #
    # Creates a COM date representation from a string date (e.g. mm/dd/yy)
    #
    year=int(strdate[6:])
    month=int(strdate[0:2])
    day=int(strdate[3:5])
    #
    # Handle possibility of pre-2000 years by using a 100 year sliding window
    #
    current_year=time.localtime()[0]
    #
    # Handle 2 digit years as well as 4 digit years
    #
    if year < 100:
        year+=1900
        if year <= (current_year-100): year+=100

    #
    # Create a DateTime instance with this information
    #
    t=DateTime(year, month, day)
    rdate=t.COMDate()
    if _trace: print "Leaving COMDateFromstrDate, COMDate=%f" % rdate
    return rdate

------------------------------

Message: 2
Date: Wed, 14 Jan 2004 17:32:17 -0500
From: Aaron Patrick Lehmann <lehmanap at cs.purdue.edu>
Subject: [python-win32] Python Dates and Windows dates
To: python-win32 at python.org
Message-ID: <20040114223217.GA13055 at lore.cs.purdue.edu>
Content-Type: text/plain; charset=us-ascii

Hello--

How do I translate from the python time format to Windows time format?

Aaron Lehmann
--
Old hold for new construction.  --Gene Ray www.timecube.com





More information about the Python-win32 mailing list