Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1347 posts 1608 karma points
    Nov 17, 2011 @ 14:07
    Gordon Saxby
    0

    Select nodes by Date but ignore Time

    in C# I am trying to select nodes where the "event" date is a specific date, but the "event" date property also includes time (i.e. it is a DateTime field).

    I tried -

    uQuery.GetNodesByXPath("$currentPage/ancestor-or-self::root//EventListPage/* [@isDoc and umbraco.library:ShortDate(eventDate) = '" + d.Date.ToShortDateString() + "']")

    but it complains about the ShortDate function.

    I suspect I may be approaching this wrong!?

     

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Nov 17, 2011 @ 14:21
    Lee Kelleher
    0

    Hi Gordon,

    The problem here is that the call that uQuery makes has no context of the "umbraco.library" class - so can't apply that logic.  Only raw/pure XPath queries will work - same applies with "umbraco.library:GetXmlNodeByXPath" method.

    Could try a substring function to truncate the string to the desired length? (I'll try to find an example)

    Cheers, Lee.

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Nov 17, 2011 @ 14:27
    Lee Kelleher
    1

    How's about something like this?

    uQuery.GetNodesByXPath("descendant::EventListPage/*[@isDoc and substring(eventDate, 1, 10) = '" + d.Date.ToString("yyyy-MM-dd") + "']")

    I removed the $currentPage part, as uQuery will query from the root node anyway, no point finding the current page navigating all the way up, then back down the XML tree again.

    Cheers, Lee.

  • Gordon Saxby 1347 posts 1608 karma points
    Nov 17, 2011 @ 15:27
    Gordon Saxby
    0

    Thanks Lee, that sorted it :-)

     

  • 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.

Please Sign in or register to post replies