Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Let's say I have a document type with alias BlogPost, which has properties:
BlogPost
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:
Where
String
DateTime
Convert.ToDateTime("blogDate") >= new DateTime("15 Dec 2014")
Is this possible to do with a Where clause?
Yes, should be like this:
var blogList = CurrentPage.AncestorOrSelf(1).Descendants("BlogPost").Where("blogDate >= @0", new DateTime("15 Dec 2014")).OrderBy("blogDate desc").Take(5);
Great - tomorrow's question answered! :)
Tony
That's great Jeavon - thank you.
I made a mistake in my initial code: new DateTime("15 Dec 2014") should be new DateTime(2014, 12, 15)
new DateTime("15 Dec 2014")
new DateTime(2014, 12, 15)
Apart from that, Jeavon's code is perfect.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Getting descendants of node using where clause in razor
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:
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 aString
, but I am attempting to compare twoDateTime
s:Is this possible to do with a
Where
clause?Yes, should be like this:
Great - tomorrow's question answered! :)
Tony
That's great Jeavon - thank you.
I made a mistake in my initial code:
new DateTime("15 Dec 2014")
should benew DateTime(2014, 12, 15)
Apart from that, Jeavon's code is perfect.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.