I'm struggling with getting a list of items via an XPATH expression involving a date and was wondering if anybody had managed it - I have code that looks like this:
var xpath = "//newsItem[@isDoc]";
var newsItemsXpath = Umbraco.ContentAtXPath(xpath).Cast<ContentModels.NewsItem>();
This selects all news items, but I'd like to select only those published in the last 30 days or so; I've googled for solutions and found various suggestions to use e.g. xs:date(@datePublished), but when I tried this:
var fromDate = DateTime.Today.AddDays(-30);
var xpath = string.Format("//newsItem[xs:date(datePublished) > '{0}'][@isDoc]", fromDate.ToIsoString());
var newsItemsXpath = Umbraco.ContentAtXPath(xpath).Cast<ContentModels.NewsItem>();
Umbraco threw an error (an invalid token) - I suppose there might be invalid data in datePublished)?
News Items have a data type called DatePublished attached, so I'm just trying to select by that - has anybody managed to select by a date using XPath?
Selecting by Date using ContentAtXPath
Hi Umbracians!
I'm struggling with getting a list of items via an XPATH expression involving a date and was wondering if anybody had managed it - I have code that looks like this:
This selects all news items, but I'd like to select only those published in the last 30 days or so; I've googled for solutions and found various suggestions to use e.g. xs:date(@datePublished), but when I tried this:
Umbraco threw an error (an invalid token) - I suppose there might be invalid data in datePublished)?
News Items have a data type called DatePublished attached, so I'm just trying to select by that - has anybody managed to select by a date using XPath?
Thanks in advance,
Chris.
is working on a reply...