Reputation: 1021
Let's say I have a document type with alias BlogPost
, which has properties:
When getting the latest 5 blogs contained in the site, I would use the following snippet:
var blogList = CurrentPage.AncestorOrSelf(1).Descendants("BlogPost").OrderBy("blogDate desc").Take(5);
However, I am trying to retrieve the latest 5 blogs where the date lies in a specific range (for example: after 15 December 2014).
I know that you can use the Where
clause with a condition contained in a String
, but I am attempting to compare two DateTimes:
Convert.ToDateTime("blogDate") >= new DateTime(2014, 12, 15)
Is this possible to do with a Where
clause?
Upvotes: 3
Views: 6332
Reputation: 1021
The snippet to do this is as follows:
var blogList = CurrentPage.AncestorOrSelf(1).Descendants("BlogPost").
.Where("blogDate >= @0", new DateTime(2014, 12, 15))
OrderBy("blogDate desc")
.Take(5)
This snippet was taken from a reply on the following Umbraco forum topic.
Upvotes: 6