Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 687 posts 1120 karma points
    May 10, 2011 @ 18:39
    Bo Damgaard Mortensen
    0

    Compare date from DatePicker datatype

    Hi all,

    I'm struggling abit with my razor code here. I have a collection of node which each has a DatePicker. In Razor I want to compare the selected day (and only day) to the current day.

    I've tried to loop through with a .Where() predicate, but there's just no way it will work. This is my code:

    var calendarRoot Model.NodeById(1059);
    foreach(var item in calendarRoot.Children.Where("item.eventDate.Day = 20"))
    {
       <span>@item.eventDate</span>
    }

    And this is the error I get when I run it:

    Error loading Razor Script Rendercalendar.cshtml

    No property or field 'eventDate' exists in type 'Func`2'

    Anyone got any hints about this? :-) Will be greatly appreciated!

    / Bo

  • Toni Becker 146 posts 425 karma points
    May 10, 2011 @ 19:41
    Toni Becker
    0

    try .Where("calendarRoot.eventDate.Day = 20")

  • Bo Damgaard Mortensen 687 posts 1120 karma points
    May 10, 2011 @ 19:50
    Bo Damgaard Mortensen
    0

    Hi Toni,

    Thanks for your input! :-)

    I tried it, but since there is no datatype on the calendarRoot called evenDate i get the following error:

    Error loading Razor Script Rendercalendar.cshtml
    No property or field 'eventDate' exists in type 'Func`2'

    :-/

    Thanks again!

    / Bo

  • Bo Damgaard Mortensen 687 posts 1120 karma points
    May 10, 2011 @ 19:57
    Bo Damgaard Mortensen
    0
    @{
      var calendarRoot Model.NodeById(1059);
      foreach(var item in calendarRoot.Children.Where("eventDate > DateTime.Now"))
      {
         <span>@item.eventDate</span>
      }  
    }

    O.k the above code works as intended, it gives me all the nodes where the selected date is greater than today. Just can't figure out how to get hold of evenDate.Day <- the daynumber.

  • Andreas Kaltenhuber 104 posts 281 karma points
    Jun 20, 2011 @ 15:22
    Andreas Kaltenhuber
    0

    Did you find a solution for your Problem?

    i'm struggling with the "same" thing. just have to check the if there is an event at an certain date an then display the date. 

    Andi

  • Dan Diplo 981 posts 3261 karma points mvp
    Jun 20, 2011 @ 22:11
    Dan Diplo
    1

    Hi,

    Here's one way - it's not "pretty" but works:

    @{
    var calendarRoot = new umbraco.MacroEngines.DynamicNode(1059);
    }


    <ul>
    @foreach (var item in calendarRoot.Descendants().Items.
    Where(i => Convert.ToDateTime(i.GetProperty("eventDate").Value).Day == 20))
    {
    <li>@Convert.ToDateTime(item.GetProperty("eventDate").Value).Date.ToShortDateString()</li>
    }
    </ul>

     
Please Sign in or register to post replies

Write your reply to:

Draft