[Zope] string splitting in dtml

Mike Kelland mike@studiomatic.com
Tue, 5 Dec 2000 14:37:28 -0500


I tried what you recommended and got the following error:

Error Type: AttributeError
Error Value: __getslice__

The problem I think is that the variable is drawn from the database as type
date (Microsoft Access 2k) and somehow is cast into a date type.  Is there a
way to re-cast this variable as a string type?  Or is there another reason
it's not working (I've tried it with my other varibles pulled from the
database in the same query and it's only the date types that are giving this
error, all other variables work fine)?

I also tried the

<dtml-var "_.string.split(start_date, '/')[1]">

solution but got the error:

Error Type: TypeError
Error Value: argument 1: expected read-only character buffer, instance found

Thanks very much for everyone's help so far!
Mike Kelland
mike@studiomatic.com

----- Original Message -----
From: "Spicklemire, Jerry" <Jerry.Spicklemire@IFLYATA.COM>
To: <mike@studiomatic.com>
Cc: <zope@zope.org>
Sent: Monday, December 04, 2000 4:38 PM
Subject: [Zope] string splitting in dtml


> Mike asked:
>
> > I have a date string (ie dd/mm/yy) which I'm drawing out of a database
> > (ODBC connection to Access) with a Z SQL method and I need to use that
> > data to set the initial condition of a set of 3 select items (ie day,
> > month and year).  Is there a way to split this date (it'll come out
> > looking like dd/mm/yy) to get the components of it
>
> You could use the Python "string slice" syntax, like so:
>
> <dtml-let day_of_month="_['start_date'][:2]"
>           month_of_year="_['start_date'][3:5]"
>           year_of_century="_['start_date'][6:8]">
> The <dtml-var day_of_month> day,<br>
> of the <dtml-var month_of_year> month,<br>
> of the year 20<dtml-var month_of_century><br>
> </dtml-let>
>
> Later,
> Jerry S.
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>
>