Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:48:05+00:00 2026-06-14T14:48:05+00:00

I have a table called Events and these are example of EndDate columns: I

  • 0

I have a table called Events and these are example of EndDate columns:

enter image description here

I am trying to extract months from these events, but I want them to be like: 11, 12, 1 (11 and 12 from current year, and 1 is from next year – 2013).

var ev = db.Events.Select(d => new { Month = d.StartDate.Value.Month, 
                                     EndDate = d.EndDate })
                  .Where(d => (d.EndDate >= DateTime.Now
                           || (   d.EndDate.Value.Day == DateTime.Now.Day 
                               && d.EndDate.Value.Month >= DateTime.Now.Month) ))
                  .OrderBy(d => d.EndDate.Value.Year)
                  .Select(d => new { Month = d.Month }).Distinct();

Well, I don’t understand why this query does not work. It extracts months as: 1, 11, 12 which of course, is not what I want…

Ps: You can ignore where clause, that is only filtering the events from now on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:48:06+00:00Added an answer on June 14, 2026 at 2:48 pm

    You are sorting on Year only .OrderBy(d => d.EndDate.Value.Year) but you probably want to sort by d.EndDate.Value

    Year only will be ignoring any days/months part of the date…so the “first” 2012 in the list is the first item.

        var events = new List<DateTime>
        {
            new DateTime(2013,11,1),
            new DateTime(2013,5,1),
            new DateTime(2013,4,1),
            new DateTime(2012,12,29),
            new DateTime(2012,12,28)
        };
    
        var ev = events.Select(d => new { Month = d.Month, Date = d })
            .Where(d => (d.Date >= DateTime.Now || (d.Date.Day == DateTime.Now.Day && d.Date.Month >= DateTime.Now.Month)))
            .OrderBy(d => d.Date.Year)
            .Select(d => new { Month = d.Month })
            .Distinct();
    

    will return 12,11,5,4

    var ev = events.Select(d => new { Month = d.Month, Date = d })
                    .Where(d => (d.Date >= DateTime.Now || (d.Date.Day == DateTime.Now.Day && d.Date.Month >= DateTime.Now.Month)))
                    .OrderBy(d => d.Date)
                    .Select(d => new { Month = d.Month })
                    .Distinct();
    

    will return 12,4,5,11

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called sellerparams with a number of columns, one of them
I have a table called Events that I want to insert information to. Here
I have a table called 'main_table' with 3 columns : 'player', 'points' and 'drop_date'
I have a table called events with 5 fields. Among those fields I have
I have a Table, called Table1, with 3 columns: 1) id - An integer
I have two tables, one called Events and one called Documents. Each table has
I have a table called Event. A column has duration--which is...how long that event
I have table called stats . In am inserting yes or no in the
i have table called as Support, which have a field named Name and contains
I have table called Buttons. Buttons table i have column button_number . Table contain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.