+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / FilterExpression - Retrieval by Date Range

FilterExpression - Retrieval by Date Range

3 posts, 0 answered
  1. Deon
    Deon avatar
    3 posts
    Registered:
    16 Dec 2011
    08 Jul 2013
    Link to this post
    I have seen mixed responses throughout the forums on the use of the FilterExpression.

    I am trying to make sure that a News List includes only news articles that are between two dates, the DateOfPublication and the ExpirationDate - both custom fields.

    In the NewsFrontendList's FilterExpression attribute, I entered the following condition:
    Visible = true AND Status = Live AND DateOfPublication <= DateTime.UtcNow AND (ExpirationDate = NULL OR ExpirationDate > DateTime.UtcNow)

    This results in an error "Error parsing the template" 

    Some of the posts mention the lack of support for "OR" in the FilterExpression.

    To experiment with this, I placed a default value of "1/1/1900" in the ExpirationDate field and changes the FilterExpression to: 
    Visible = true AND Status = Live AND DateOfPublication <= DateTime.UtcNow AND (ExpirationDate < (1/1/1900 23:59) OR ExpirationDate > DateTime.UtcNow)

    Since the latter worked, I have no doubt that the FilterExpression now supports "OR".

    What I am still looking to do is instead of require a date, I would like the former, or some variant thereof, to work.  

    I would preferably like to resolve this without a coding solution.  Anyone?

     
  2. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    11 Jul 2013
    Link to this post
    Hi Deon,

    You have been given an answer in the support ticket you have opened. I will paste the answer below:


    In order to check if the  ExpirationDate field has been populated with a value or not in the FilterExpression you can modify your filter like so:

    Visible = true AND Status = Live AND DateOfPublication <= DateTime.UtcNow AND (
    !ExpirationDate.HasValue
    OR ExpirationDate > DateTime.UtcNow)


    Regards,
    Pavel Benov
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Deon
    Deon avatar
    3 posts
    Registered:
    16 Dec 2011
    11 Jul 2013 in reply to Pavel Benov
    Link to this post
    Thanks.  That worked perfectly.
3 posts, 0 answered