Forum Discussion

SaraFennah's avatar
Aug 18, 2016

Content Query Web Part and Dates

Whilst more of an advanced user rather than a developer myself, I think only a developer can answer my question.  I am trying to display a list of entries from my custom list where the [Order Date] is this week (i.e. after Monday in the current week).  I don't believe this can be done via the query in CQWP, however I was hoping I could get users to input the week start date into a control on the page and use that field to set the value in the CQWP.

 

Otherwise the CQWP gives exactly what is needed, just need a way to set the date in the query to Monday.  Any advice?  Ideally no code solutions.

    • SaraFennah's avatar
      SaraFennah
      MVP
      Thanks for the tips. The 7 day filtering around today won't work in this scenario as the view needs to only show current week not last 7 days. Current week being Monday to Sunday. So on a Monday, I need to see only today, on Tuesday today and yesterday, etc.
      • Waldek Mastykarz's avatar
        Waldek Mastykarz
        Copper Contributor

        One way to go around it would be to define a query that would get items from previous 7 days to next 7 days: that way you would be safe on Sunday (getting items from the past week) as well as on Monday (getting items from the upcoming week). You could then sort items ascending by the date and do filtering in XSLT. The ddwrt namespace contains some date manipulation functions that could help you with that. It's not trivial but it's definitely doable. It's worth noting that this approach would work if the list of items is not huge and retrieving items from -7 days to + 7 days wouldn't return hundreds of items.

         

        Hope this helps,

         

        Waldek

  • You can use the content Query web part for this however you might want to try using the Search results or Content Search web part. Then you can use Display templates instead of xsl. And specify queries through the interface.

Resources