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 9319237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:20:03+00:00 2026-06-19T03:20:03+00:00

I have a data object that has a timestamp: class MyDataObject { public DateTime

  • 0

I have a data object that has a timestamp:

class MyDataObject
{
    public DateTime timestamp { get; set; }
    public int value { get; set; }

    public MyDataObject(DateTime timestamp, int value)
    {
        this.timestamp = timestamp;
        this.value = value;
    }
}

In the main method, I create a lot of these data objects over the timespan of 18 days (2.5 weeks):

    static void Main(string[] args)
    {
        List<MyDataObject> data = new List<MyDataObject>();

        data.Add(new MyDataObject(DateTime.Now, 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(2), 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(4), 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(6), 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(8), 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(10), 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(12), 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(14), 1));
        data.Add(new MyDataObject(DateTime.Now.AddDays(18), 1));
    }

I need to divide this data by weeks, so that the data between days 1 to 6 need to be placed in an array, data between days 8 to 14 in another, and the one in day 18 goes in another array all by itself.

I need to create a 2D List of some sort and somehow divide the data in an “array of arrays” but I’m stumped. I suspect I need to use List.FindAll but I’ve never used it before and have no idea how I can use it in this case.

  • 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-19T03:20:04+00:00Added an answer on June 19, 2026 at 3:20 am

    Assuming you can use LINQ, you’d just want something like:

    var groupedByWeek = data.GroupBy(item => GetStartOfWeek(item.timestamp));
    

    … where GetStartOfWeek would return a DateTime at the start of the given week, e.g.

    public static DateTime GetStartOfWeek(DateTime value)
    {
        // Get rid of the time part first...
        value = value.Date;
        int daysIntoWeek = (int) value.DayOfWeek;
        return value.AddDays(-daysIntoWeek);
    }
    

    That will give you a Sunday-based week. You’d need to adjust it a bit to consider a week starting on Saturday, Monday or whatever.

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

Sidebar

Related Questions

I have a serializable Message class that has a Data As Object property that
I have an object that has a property: [Column] public Binary Image { get;
I have a data object (let's say it's called 'Entry') that has a set
I have a object that contains data from a DB. The object has a
I have a data object that is deep-cloned using a binary serialization. This data
I have a data object that looks like this: { 'node-16': { 'tags': ['cuda'],
I have a data object -- a custom class called Notification -- that exposes
I have an object called EmailMessage, which has a nullable System.DateTime field called Timestamp.
I have a core data object that has a bunch of optional values. I'm
I have a Pandas Data Frame object that has 1000 rows and 10 columns.

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.