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

  • SEARCH
  • Home
  • 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 6990091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:18:03+00:00 2026-05-27T19:18:03+00:00

I am writing an Excel exporter for a bespoke application I am creating, and

  • 0

I am writing an Excel exporter for a bespoke application I am creating, and I have a question about LINQ grouping in C#.

Basically, this new Excel exporter class is given two dates. The class then retrieves all consignments between this date range.

As part of this exporter, I need to be able to group the dates into weeks, and get the values for that week. So for example, if I’m given 07/12/2011 and 22/12/2011 (dd/MM/yyyy format), I need to group all consignments between them ranges into weeks (each week beginning with Sunday). The ideal result using the above dates would be

Week 1: (consignments between 04/12/2011 and 10/12/2011) 
Week 2: (consignments between 11/12/2011 and 17/12/2011) 
Week 3: (consignments between 18/11/2011 and 24/12/2011)

Any ideas?

  • 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-05-27T19:18:04+00:00Added an answer on May 27, 2026 at 7:18 pm

    The fundamental question here is how to project a DateTime instance into a week of year value. This can be done using by calling Calendar.GetWeekOfYear. So define the projection:

    Func<DateTime, int> weekProjector = 
        d => CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(
             d,
             CalendarWeekRule.FirstFourDayWeek,
             DayOfWeek.Sunday);
    

    You can configure exactly how the “week number” is determined by tweaking the parameters in the method call. You can also decide to define the projection as e.g. an extension method if you prefer; this does not change the essence of the code. In any case, you are then ready to group by week:

    var consignmentsByWeek = from con in consignments
                             group con by weekProjector(con.Date);
    

    If you also want to constrain the output to consigments between two specific dates, just add an appropriate where clause; the grouping logic does not change.

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

Sidebar

Related Questions

I am currently writing an application that will perform automation in Excel. I have
I am writing an excel class and i want to release this unmanaged object
I have an Python ExcelDocument class that provides basic convenience methods for reading/writing/formatting Excel
I'm writing an Excel Addin using COM Interop from .net. I have a command
Good morning, I am about to start writing an Excel add-in for Excel 2002.
I started writing a small wrapper class to take care of my excel operations:
I am new to writing excel add-in (in C#) and trying to figure out
I am interested in writing an application that will take in an excel document
I am writing a C# Console Application and I am correctly opening an Excel
I'm writing a Excel class using Microsoft.Interropt.Excel DLL. I finish all function but I

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.