Copied to clipboard

Flag this post as spam?

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

  • Simon Hewitt 65 posts 126 karma points
    Nov 28, 2012 @ 12:14
    Simon Hewitt

    Filter by month and year

    Hi folks I currently have;

    var nodes = Model.Descendants("saEvent").Where("eventStartDateTime <= DateTime.Now && eventEndDateTime >= DateTime.Now");

    Which works fine but I'd like to be able to page through events by month which means I would have to pass in a month and year via the querystring but I'm not sure how to convert my document properties into month and year variables in the where clause.

    What's the best way of tackling this issue, I'm assuming doing my filtering in the where clause will be faster than grabbing all the documents and looping over them.

    Any help appreciated!



  • Douglas Ludlow 210 posts 366 karma points
    Nov 28, 2012 @ 16:18
    Douglas Ludlow

    Hey Simon,

    If your properties are from datepickers than they are going to come through as DateTime objects, so something like this should work, for months at least:

    var nodes = Model.Descendants("saEvent").Where("eventStartDateTime.Month <= DateTime.Now.Month && eventEndDateTime.Month >= DateTime.Now.AddMonths(1).Month");
  • Simon Hewitt 65 posts 126 karma points
    Nov 28, 2012 @ 17:13
    Simon Hewitt

    Brilliant, it didn't occur to me I would have access to properties like .Month, thats just made my life a lot easier.



Please Sign in or register to post replies

Write your reply to: