Search the FirstSpirit Knowledge Base
Hello community,
I have to get all entries within the last x weeks from my news-table.
The select is not that difficult, but how do I get the right entry.
<CMS_FUNCTION name="contentSelect" resultname="fr_cs_news">
<CMS_PARAM name="schema" value="schema-name" />
<QUERY entityType="news">
<GTE attribute="date" datatype="java.util.Date" value="1281006562000"/>
</QUERY>
</CMS_FUNCTION>
Any ideas? Is it some how possible?
Thanks in advance.
"day_of_week" is definitely wrong, this is the week day (monday, tuesday, etc.)!
I would recommend #startdate + (-7 * 24 * 60 * 60 * 1000):
<CMS_FUNCTION name="contentSelect" resultname="thisWeek">
<CMS_PARAM name="schema" value="schema-name" />
<CMS_VALUE_PARAM name="d" value="#startdate + (-7 * 24 * 60 * 60 * 1000)"/>
<QUERY entityType="news">
<FILTERPARAM parameter="von" datatype="java.util.Date" value="0"/>
<AND>
<GTE attribute="date" parameter="d"/>
</AND>
<ORDERCRITERIA attribute="date" descending="0" />
</QUERY>
</CMS_FUNCTION>
Just look at javascript:;
here the solution for this specific request:
<CMS_FUNCTION name="contentSelect" resultname="thisWeek">
<CMS_PARAM name="schema" value="schema-name" />
<CMS_VALUE_PARAM name='von' value='#startdate.set("day_of_week",-7).set("hour",0).set("minute",0).set("second",0).getTime()' />
<QUERY entityType="news">
<FILTERPARAM parameter="von" datatype="java.util.Date" value="1232977740000"/>
<AND>
<GTE attribute="date" parameter="von"/>
</AND>
<ORDERCRITERIA attribute="date" descending="0" />
</QUERY>
</CMS_FUNCTION>
For two weeks use "day_of_week",-14 instead of -7 and so on...
I believe in all the magic you do, but this doesn't work for me!
#startdate.set("day_of_week",0).set("hour",0).set("minute",0).set("second",0).getTime()
returns me the day after tomorrow, just like every multiple of -7.
Is it possilbe that it has to do something with the server-settings?!?
"day_of_week" is definitely wrong, this is the week day (monday, tuesday, etc.)!
I would recommend #startdate + (-7 * 24 * 60 * 60 * 1000):
<CMS_FUNCTION name="contentSelect" resultname="thisWeek">
<CMS_PARAM name="schema" value="schema-name" />
<CMS_VALUE_PARAM name="d" value="#startdate + (-7 * 24 * 60 * 60 * 1000)"/>
<QUERY entityType="news">
<FILTERPARAM parameter="von" datatype="java.util.Date" value="0"/>
<AND>
<GTE attribute="date" parameter="d"/>
</AND>
<ORDERCRITERIA attribute="date" descending="0" />
</QUERY>
</CMS_FUNCTION>
That works! Thanks a lot!
pjodeleit schrieb:
"day_of_week" is definitely wrong, this is the week day (monday, tuesday, etc.)!
Hmm - but:
Starttime: $CMS_VALUE(#startdate.set("day_of_week",2).set("hour",0).set("minute",0).set("second",0).format("dd.MM.yyyy hh:mm:ss"))$<br>
Endtime: $CMS_VALUE(#startdate.set("day_of_week",2).add("day_of_week",7).set("hour",0).set("minute",0).set("second",0).format("dd.MM.yyyy hh:mm:ss"))$<br>
creates:
Startime: 23.08.2010 12:00:00
Endtime: 30.08.2010 12:00:00
tested with FirstSpirit Version 4.2.219
Hint: In most cases you do want to get all news from a specific day/week/month/year on. So it is a good idea to set the startdate to midnight of the appropriate day
The mistake in the first posting was:
#startdate.set("day_of_week",-7)
correct would have been
#startdate.add("day_of_week",-7)
Thanks Gockel and sorry,
Holger