ASP + SQL Server + Time object problem

David A. Fuess fuess at home.com
Sat Jan 27 18:15:36 EST 2001


There are several problems with the use of strftime here. When using
the <time object> delivered by SQL server the datum is not the same as
the UNIX datum and the float(<time object>) returns days instead of
seconds. Also, as was mentioned before, even after correcting for the
datum difference you cannot use dates before the UNIX datum Jan 1,
1970.

For SQL Server 7 I found the datum conversion to be
	Unixtime = (float(contents)-25569.0)*86400+time.timezone
I had to put in the timezone correction because SQL Server was
converting times to GMT. Then I had to abandon the whole approach
because many of the dates in my database are pre 1970!

I found the best way to deal with These objects is the Format method.
By trial and error I deduced that it uses the same specifiers as
strftime.

Dave

abramsjc at my-deja.com wrote:

>Hi again, thanks for the responses.
>Here's what I came across. I should have specified that I import a module
>and within a class in that module is where the problem was being
>experienced. I read the docs by that genuis guy Mark, but trying to use
>the PyTime objects gave me errors about no __float__ attribute and other
>errors when trying different methods.
>
>> To return a string formatted as the long date in control panel
>> time.strftime("%#c", time.localtime(int(timeObject)))
>
>See that int() conversion, that fails. What I found out that it was because
>the code lied in the module. If I return the time object to the top-level ASP
>script, the int conversion works, PyTime objects work, it all works.
>But inside that imported module nothing worked. Pretty weird. Anyone
>know why?
>
>
>
>In article <93p88d013hg at news1.newsguy.com>,
>  "Alex Martelli" <aleaxit at yahoo.com> wrote:
>> "Tim Hammerquist" <tim at degree.ath.cx> wrote in message
>> news:slrn95vghv.aqj.tim at degree.ath.cx...
>>     [snip]
>> > Anyone in the newsgroup familiar with the object model of a "time
>> > object"?
>>
>> Hammond's docs included with win32all document it this way:
>>
>> PyTime Object
>> A Python object, representing an instant in time.
>>
>> Comments
>> A PyTime object is used primarily when exchanging date/time information with
>> other COM objects.
>> Using int(timeObject) will return an integer compatible with the time
>> module.
>>
>> Example
>> To return a simple string
>> time.ctime(int(timeObject))
>>
>> To return a string formatted as the long date in control panel
>> time.strftime("%#c", time.localtime(int(timeObject)))
>>
>> See Also
>> pywintypes::Time
>>
>> Methods
>> Format
>> Formats the time value
>> __int__
>> Used when an integer representation of the time object is required.
>> __float__
>> Used when a floating point representation of the time object is required.
>> __print__
>> Used when the time object is printed. tp_print
>> __cmp__
>> Used when time objects are compared. tp_compare
>> __hash__
>> Used when the hash value of an time object is required tp_hash
>>
>> Seems pretty good to me -- what's missing?
>>
>> Alex
>>
>>
>
>
>Sent via Deja.com
>http://www.deja.com/




More information about the Python-list mailing list