Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    May 23, 2013 @ 16:27
    Ravi Motha
    0

    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)

     

  • Lotte Pitcher 49 posts 242 karma points MVP 7x c-trib
    May 23, 2013 @ 17:33
    Lotte Pitcher
    0

    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);
  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    May 23, 2013 @ 17:40
    Ravi Motha
    0

    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

  • Mike Chambers 636 posts 1253 karma points c-trib
    May 24, 2013 @ 10:40
    Mike Chambers
    0

    you could revert to linq... some code here..

    http://issues.umbraco.org/issue/U4-1032

Please Sign in or register to post replies

Write your reply to:

Draft