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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:34:46+00:00 2026-06-14T04:34:46+00:00

Linq from c in customerReadings group c by new { date = GetGroupingDateKey(DateRangeType, c.ReadDate),

  • 0

Linq

from c in customerReadings
group c by new { date = GetGroupingDateKey(DateRangeType, c.ReadDate), name = c.Name } into g
select new MeterReadingsForChart
{
    ReadDate = g.Key.date,
    Name = g.Key.name,
    Value = g.Sum(y => y.Value),
    TimeInterval = DateRangeType
};

GetGroupingDateKey()

private static DateTime GetGroupingDateKey(MeterReadingsTimeIntervals DateRangeType, DateTime Date)
{
    DateTime date = new DateTime();
    switch (DateRangeType)
    {
        case MeterReadingsTimeIntervals.Hourly:
            //For Example data is betweet 10:05 - 11:05
            //DateTime offSet = Date.AddMinutes(-5);
            //date = new DateTime(offSet.Year, offSet.Month, offSet.Day, offSet.Hour, 5, 0);
            date = new DateTime(Date.Year, Date.Month, Date.Day, Date.Hour, 0, 0);
            break;
        case MeterReadingsTimeIntervals.Daily:
            date = new DateTime(Date.Year, Date.Month, Date.Day, 0, 0, 0);
            break;
        case MeterReadingsTimeIntervals.Weekly:
            date = Date.AddDays(-((7 + Date.DayOfWeek - DayOfWeek.Monday) % 7));
            break;
        case MeterReadingsTimeIntervals.Monthly:
            date = new DateTime(Date.Year, Date.Month, 1, 0, 0, 0);
            break;
        case MeterReadingsTimeIntervals.Yearly:
            date = new DateTime(Date.Year, 1, 1, 0, 0, 0);
            break;
    }

    return date;
}

Records time : 10/10/2012 – between 09:15 and 10:15

Hourly groupped data count  : 2 (expected)

Daily groupped data count   : 1 (expected)

Weekly groupped data count  : 5 (group count (not expected))

Monthly groupped data count : 1 (expected)

Yearly groupped data count  : 1 (expexted)

How can I group records by week. What is the wrong about my weekly grouping?

Thanks in advance.

  • 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-14T04:34:47+00:00Added an answer on June 14, 2026 at 4:34 am

    I would imagine your Date has a time part – you need to zero it out, e.g.

    date = Date.Date.AddDays(-((7 + Date.DayOfWeek - DayOfWeek.Monday) % 7));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this is a standard Linq from q in SomeQuery select new SomeObject {
Here's my linq from G in Gestion select new { GestionInicio = G.HoraInicio, GestionFin
I am using LINQ like from a in b.Descendants(SomeNode) select new MyClass { isfirst=
Simple LINQ query: from transport in db.Transports select new { Current = transport.CurrentLocation, CurrentCarriers
Here is my LINQ query: (from o in entities.MyTable orderby o.MyColumn select o.MyColumn).Distinct(); Here
I want to generate this SQL statement in LINQ: select * from Foo where
I'm trying to do the following query in Linq SELECT * FROM Table1 T1
I am new to linq.From the list of following data,help me how can i
I have the following linq query from c in AllContracts group c.StatusId by c.StatusDescription
hi i want to select multiple db from linq in same select statement //

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.