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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:40:18+00:00 2026-05-16T14:40:18+00:00

I have an IEnumerable of an item class defined like this: public class Item

  • 0

I have an IEnumerable of an item class defined like this:

public class Item {
    public DateTime Date { get; private set; }
    public decimal? Value { get; private set; }

    public Item(DateTime date, decimal? value) {
     Date = date;
     Value = value;
    }
}

These items are in a specific time interval (5 minutes for exemple). I need to group them by the date, but changing the interval. For example, if the items are in the following order:

2010-08-24 00:05
2010-08-24 00:10
2010-08-24 00:15
2010-08-24 00:20
2010-08-24 00:25
2010-08-24 00:30

and I want to group them into a 15 minutes interval, the result should look like this:

2010-08-24 00:15
2010-08-24 00:30

The interval is provided by another class, but I can get the milliseconds that represent that interval (for example, Interval.FromMinutes(5).GetMilliseconds() should return 300000). The question is how can I write a grouping function that allows me to do something like this : data = items.GroupBy(t => GroupingFunction(t.DateTime, interval)) and obtain that result?

Update: the interval will not be necessarily in minutes. It could be in hours, minutes or even days.

  • 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-16T14:40:18+00:00Added an answer on May 16, 2026 at 2:40 pm

    Something like this ?

            DateTime[] dateTimes = new[]
                                       {
                                           new DateTime(2010, 8, 24, 0, 5, 0),
                                           new DateTime(2010, 8, 24, 0, 10, 0),
                                           new DateTime(2010, 8, 24, 0, 15, 0),
                                           new DateTime(2010, 8, 24, 0, 20, 0),
                                           new DateTime(2010, 8, 24, 0, 25, 0),
                                           new DateTime(2010, 8, 24, 0, 30, 0)
                                       };
            TimeSpan interval = new TimeSpan(0, 15, 0);     // 15 minutes.
    
            var groupedTimes = from dt in dateTimes
                               group dt by dt.Ticks/interval.Ticks
                               into g
                               select new {Begin = new DateTime(g.Key*interval.Ticks), Values = g.ToList()};
    
            foreach (var value in groupedTimes)
            {
                Console.WriteLine(value.Begin);
                Console.WriteLine("\t{0}", String.Join(", ", value.Values));
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the a class Foo like this: class Foo { public int id{get;set;}
I have an extension method defined like so: public static TSource MaxBy<TSource, TResult>(this IEnumerable<TSource>
I have the following class hierarchy. class Header { IEnumerable<Item> Item { get; set;
I have an Entity object, Item, that looks like this.. public class Item() {
I have the following: class Item { public object ItemId {get;set;} } class StringItem
I have this C# code: abstract class MyList : IEnumerable<T> { public abstract IEnumerator<T>
NOTE: Depends on this quetion I have a view-model like this: public class ViewModel
I have such class: public class Foo { public string Regn{get;set;} public string DocName{get;set;}
I have an IEnumerable< T> which is declared on the page like this: IEnumerable<
I have an IEnumerable<DateTime> . I would like to pull out all dates that

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.