FilterExpression - Retrieval by Date Range

Posted by Community Admin on 04-Aug-2018 23:33

FilterExpression - Retrieval by Date Range

All Replies

Posted by Community Admin on 08-Jul-2013 00:00

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?

 

Posted by Community Admin on 11-Jul-2013 00:00

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

Posted by Community Admin on 11-Jul-2013 00:00

Thanks.  That worked perfectly.

This thread is closed