[Zope] Problems with date format

J Cameron Cooper jccooper at jcameroncooper.com
Thu Nov 13 20:56:12 EST 2003


Andre Dourado wrote:

> When I input a date in a DTML Form, I use the "%d/%m/%Y" format, but 
> that date field must be stored in a MS SQL Server database 
> in "%m/%d/%Y" format. I've tried to store that field using: 
> <dtml-sqlvar date_field.strftime('%m/%d/%Y') type=string> but an error 
> ocurred.

Hint: when an error occurs, it's always more helpful to actually supply 
the error. Luckily, this isn't one that requires mind-reading.

To write a Python expression in DTML, it must be notated as such, 
otherwise it will be interpreted simply as a name. To tell DTML you're 
using a Python expression rather than a name, you say::

 expr="..."

or the shorthand::

 "..."

in place of the name you usually hand it. So your code should be::

<dtml-sqlvar "date_field.strftime('%m/%d/%Y') " type=string>

You may also need to enclose the type value in quotes too: I forget the 
exact DTML syntax.

             --jcc

-- 
"Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."
(http://www.devx.com/java/editorial/15511)





More information about the Zope mailing list