How do I format date/time in dtml from a ISO-8601 SQL timestamp field? field?
I am probably missing something simple here, however I can not get this to work properly.... Given mtime = YYYY-MM-DD HH:MM:SS-ZZ as returned from PostgreSQL, how do I get the following to work without errors? <dtml-in "sqlquery(...)"> .... <dtml-var mtime fmt="%a %d %b %Y %H:%M:S %Z"> .... </dtml-in query> This returns: Errot Type: ValueError Error Value: unsupported format character 'a' (0x61) If i drop the %a from the fmt string as follows: <dtml-in "sqlquery(...)"> .... <dtml-var mtime fmt="%d %b %Y %H:%M:S %Z"> .... </dtml-in query> I get the following Zope Error: Error Type: Type Error Error Value: illegal argument type for built-in operation Mtime was initially declared as a string in the ZSQL Method arguments list, and changing it to date had no effect. I have searched the documentation and all examples I have found that use strftime formatting indicate that this should work. I have successfully been able to change the format using the to_char(mtime) PostgreSQL function, but then order by mtime does not work properly and besides, I would like to make the format style customizable from within Zope instead of on the SQL server. Thanks in advance for any suggestions.... Regards, Jarrod Kinsley
On Thu, 19 Oct 2000, J Kinsley wrote:
Given mtime = YYYY-MM-DD HH:MM:SS-ZZ as returned from PostgreSQL, how do I get the following to work without errors?
<dtml-in "sqlquery(...)"> .... <dtml-var mtime fmt="%a %d %b %Y %H:%M:S %Z"> .... </dtml-in query>
This returns: Errot Type: ValueError Error Value: unsupported format character 'a' (0x61)
AFAIK the fmt cannot be used like that What I usually do is create a DateTime object and then use the DateTime's methods and string formatting e.g. <dtml-with "_.DateTime(mtime)"> <dtml-var "'%i-%s-%s' % (year(), mm(), dd())"> </dtml-with> Modify the above for your needs. A list of DateTime's methods can be found in the appendix of the DTML Users Guide HTH, Stefan
participants (2)
-
J Kinsley -
Stefan H. Holek