Search code examples
dotnetnuke2sxc

ValueFilter for DateTime Attributes


I'm working with the Blog app and I see how to filter the Blog posts by year using the Visual Query Designer. I use the querystring value that has the year and in the ValueFilter and my properties are as follows: Attribute: PublicationMoment Value: [QueryString:year]-01-01 and [QueryString:year]-12-31 Operation: between

How would I get the posts from a specific month and year, if those values are passed via query string parameters. Because the months of the year have a varying number of days, I'm not sure how you would accomplish this in the Value field of the ValueFilter. Currently I'm passing the 2 digit month as the parameter.

I tried something like: [QueryString:year]-[Querystring:month] Operation: contains but the above operation doesn't really work because the datatype is a DateTime object.

I could do it in the razor view but I'm afraid that the paging datasource would have too many pages in it since it would be based on the larger subset of posts for the given year that was passed in the querystring parameter.

Is there any way to do this with the filter?


Solution

  • Basically dates are not perfectly handled yet, but there are a few ways to do it using the visual query:

    1. Use the correct date in the query like between [QueryString:Start] and [QueryString:End] and calculate the correct dates there where you generate the links
    2. Since your main problem with the "between" filter is actually that it would include the last day too, you could also use a two filters a >= first date and another < second date, so the first-date would be the year/month and day 1; the second one is year-month and day 1 as well

    Last but not least: if you do it with razor and LINQ you shouldn't run into any performance issues - it's technically the same thing the pipeline does and it's been tested to perform well with tens of thousands of records.