Copied to clipboard

Flag this post as spam?

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


  • Jothipriya G 8 posts 110 karma points
    Feb 25, 2022 @ 14:48
    Jothipriya G
    0

    How to get current month event

    Hi Everyone,

    I have created a 6 events. In that 3 was created in January and another 3 was created in February. I want to fetch the events created in current month. For that I have used query builder in Umbraco and the query was

    @{
        var selection = Umbraco.Content(Guid.Parse("9359beaa-b580-4f2c-8c8f-239f29e560b4"))
        .ChildrenOfType("aseanEventsItem")
        .Where(x => (x.CreateDate >= DateTime.Now.Date))
        .Where(x => x.IsVisible());
    }
    <ul>
        @foreach (var item in selection)
        {
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    I'm getting today created event but how to get it month wise????

    -Jothipriya

  • Damian 74 posts 397 karma points
    Mar 01, 2022 @ 16:02
    Damian
    0
    .Where(x => (x.CreateDate.Month >= DateTime.Now.Month))  // swap Date with Month
    

    Using an IDE like VisualStudio or JetBrains' Rider will give you some magic-like autocomplete called Intellisense that helps you discover what options are available to objects and other aspects fof your code in order to construct queries, etc… Hope this helps!

    *edited with adding .Month on the tail of the CreateDate as Harikrishna points out below. I expanded from a simpler posting and didn't catch all the pokemon along the way

  • Harikrishna Parmar 43 posts 262 karma points c-trib
    Mar 01, 2022 @ 17:21
    Harikrishna Parmar
    101

    Hi Jothipriya,

    if you want to get all events created in current month, You should try this condition:

    .Where(x => x.CreateDate.Month == DateTime.Now.Month)
    

    Hope this will help you!!

    Thanks, Harikrishna.

  • Damian 74 posts 397 karma points
    Mar 01, 2022 @ 20:43
    Damian
    0

    good catch - high five!

  • Jothipriya G 8 posts 110 karma points
    Mar 03, 2022 @ 05:34
    Jothipriya G
    0

    Yeah! It's working good thankyou.

Please Sign in or register to post replies

Write your reply to:

Draft