[Zope] on dates

Les Ferguson lhf at xtra.co.nz
Mon Oct 11 14:49:10 EDT 2004


I am using this in a query to MySql...

    SELECT Job_id, DATE_FORMAT(Job_Date,"%d %b %Y") as Job_Date
    FROM Jobs  ...etc...

This allows me to retrieve Job_Date how ever I need it at the time. The 
format codes for MySql are similar to strftime in Python.  Also, from 
within a python script I have used:

    today=DateTime().strftime("%d %b %Y")

The DateTime() type should be available in your script environment, and 
I believe you can pass your data value to DateTime() and it will 
initialize to a valid Python datetime object.

-- 
Les Ferguson
Software developer
Waitakere, NZ

-- 
massimop at users.berlios.de wrote:
> On Mon, 2004-10-11 at 18:57 +0100, Cliff Ford wrote:
> 
>>You could try writing a wee Python script. This one gets the date from 
>>the query:
>>
>>for result in context.theQuery():
>>     print result.theDate.strftime('%H:%M, %a %d %b, %Y')
>>return printed
>>
>>Then call the script from the template.
>>
>>Alternatively, you could pass the date string to the Python script.
>>
>>Actually, I call a dtml object from a template, and the dtml calls the 
>>script (because the dtml has some extra HTML layout and the python does 
>>the date formatting - so the template looks uncomplicated).
>>
>>Cliff
>>
> 
> 
> following your suggestion (if I've understood) I tried this script:
> 
> ## Script (Python) "formatdate_py"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=d
> ##title=
> ##
> # Import a standard function, and get the HTML request and response
> objects.
> from Products.PythonScripts.standard import html_quote
> request = container.REQUEST
> RESPONSE =  request.RESPONSE
> 
> return d.day
> 
> 
> and then called it from a page template with:
> 
> <i tal:content="python: here.formatdate_py(item.data)"></i>
> 
> but it's sadly the same...
> 
> <<You are not allowed to access 'day' in this context>>
> 
> and it dosn't change if I pass 'item' to the script an access the field
> 'data' inside it
> 
> 
> thanks for your help
> massimo
> 
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
> 


More information about the Zope mailing list