Can you solve it by working out what date range you need? I have got date range criteria working for comparing against DatePicker data types . Something like this might work perhaps?
//get your criteria into two DateTime variables, e.g. var fromDate = System.DateTime.Now; var toDate = fromDate.AddMonths(1);
//build where clause and dictionary of the 'where' parameters var values = new Dictionary<string, object>(); var where = "newsDate >= fromDate && newsDate <= toDate"; values.Add("fromDate", fromDate); values.Add("toDate", toDate);
//get matching items var news_items = Model.AncestorOrSelf().Descendants("NewsItem").Where(where, values);
datetime .Where clause help
having a brain block..
but can I
var month = 4;
var year
var news_items = @Model.AncestorOrSelf().Descendants("NewsItem");
orderedNewsItems = news_items.Where("DateTime.Parse(\"newsDate").Month == \"@month\")
orderedNewsItems = news_items.Where("DateTime.Parse(\"newsDate").Month == \"@month\" && "DateTime.Parse(\"newsDate").Year== \"@year\" );
do that or do I have to go about it a different way (newsdate comes from a date picker)
Can you solve it by working out what date range you need? I have got date range criteria working for comparing against DatePicker data types . Something like this might work perhaps?
That would work It just feels like I should be able to to do the datetime.parse in the where.. right now I am getting 0 results
orderedNewsItems = news_items.Where("DateTime.Parse(\"newsDate\").Month == " + @qsMonth + "").Where("DateTime.Parse(\"newsDate\").Year == " + @qsYear + "");
Don't know why though.. grr shales fist at world..
Will try you way
ta muchly
rv
you could revert to linq... some code here..
http://issues.umbraco.org/issue/U4-1032
is working on a reply...