rbitdd
Returning Responder

Looking for date x weeks ago.

Jump to solution

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.

0 Kudos
1 Solution

Accepted Solutions

"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>

Peter

View solution in original post

0 Kudos
6 Replies
hoebbel
Crownpeak employee

Just look at javascript:; Smiley Wink

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...

0 Kudos
rbitdd
Returning Responder

I believe in all the magic you do, but this doesn't work for me! Smiley Sad

#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?!?

0 Kudos

"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>

Peter
0 Kudos

That works! Thanks a lot! Smiley Happy

0 Kudos

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 Smiley Wink

0 Kudos
hoebbel
Crownpeak employee

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 Smiley Happy and sorry,

  Holger

0 Kudos