Could not convert date: ${tocDate}

Here’s what we’re trying to do. We have a monthly newsletter, and on the page template there is a image and link to that months print edition of our magazine. Rather then do a manual slot where the user add’s the coverImageLink snippet I want to try and automate this, so that when the user creates a newsletter for May then May’s print edition cover/link gets auto insert on the slot.

What I’ve done is create a autoSlot with no query.

I then created the following binding’s on my PgNewsletter template:

$tocDate = $sys.item.getProperty(“sys_contentstartdate”).date

$param.query = “select rx:sys_contentid, rx:img1, rx:img_alt, rx:img1_type from rx:camagPeContent WHERE sys_lang = ‘en-ca’ AND
sys_contentstartdate = ‘${tocDate}’”

I also added one for max_results and template to use. My thinking is that if the start date of the newsletter matches the date of the print edition then it should display.

The error I get however is "Could not convert date: ${tocDate}.

Does anyone have any ideas here?

Add .class.name to the end of $sys.item.getProperty(“rx:sys_contentstartdate”).date and you’ll find it is an object of type java.util.GregorianCalendar (at least on 6.5.2.) You need to use a method of that class, or its parent class, or a method of the $tools.date object that provides access to the Velocity Date Tool to convert it to a string in a format that will work in a JSR-170 query (discovering what that might be will probably require some experientation on your part using the Rhythmyx Query Debugger.)

Note also that you do not need to list the fields you want to access in the JSR-170 query. All you need is…

SELECT rx:sys_contentid, rx:sys_contentstartdate FROM ...

…adding what I presume is a binary field containing an uploaded image (rx:img1) could slow down the query significantly. You need to handle that in the binary and snippet templates.

Hi I was working on very similar issue today so I can relate… I ended up having to convert my dates so that I could compare them (and in my case use them for an autoslot where I am pulling all events where startdate is equal or greater than today’s today minus 1 year). I was not able to compare or manipulate the dates using java.util.GregorianCalendar so I had to get everything converted as a java.util.Date:

to get it to work I added the following bindings on my template:
$rawstartdate --> $sys.item.getProperty(“rx:sys_contentcreateddate”).date
$convertedstartdate --> $tools.date.toDate($rawstartdate)
$compare.today --> $tools.date.getDate()
$compare.startdate -->
$today --> $tools.date.getCalendar()
$ayearago --> $today.add(5,-365)
$comparedate --> $today
$convertedcomparedate --> $tools.date.toDate($comparedate)
$compare.comparedate --> $convertedcomparedate

All of which are added in the template where i am calling my autoslot…
I am just calling it as follows

#slot(‘last365daysnews’ ‘’ ‘’ ‘’ ‘’ $compare)

The autoslot uses the following query:

SELECT rx:sys_contentid, rx:sys_contentstartdate FROM rx:News where rx:sys_contentstartdate>=:comparedate ORDER BY rx:sys_contentstartdate desc

Not the most elegant solution I admit but returns the data I am after… if anyone has come up with a more elegant solution I would love to see it :slight_smile:

Hope it helps

Excellent thanks Celine that seems to have done the trick.

Correction, make that…

SELECT rx:sys_contentid, rx:sys_folderid FROM ...

…see this post