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

The Archive Base Latest Questions

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

I have table with below fields, table Shows, Id Name Time 1 A 7/28/2010

  • 0

I have table with below fields,

table Shows,
  Id   Name   Time
   1     A    7/28/2010 11:15:00 AM
   2     B    7/29/2010 8:50:00 AM
   3     C    7/29/2010 8:55:00 AM

I have an object Show that has data from all the fields. Now I want to have a UI,
that displays count of shows on an hourly basis for all days..

Date 7/28/2010
  Hours Count
  11-12   1

Date 7/29/2010
  Hours Count
  8-9   2

I have no idea how I shall do it in C#(the logic for it.)Also, is there something like a explode funtion that we have in php, in C#. Because my database field has value
7/29/2010 8:55:00 AM and I want to break date and time. Can anybody help with logic to build the above UI?

As I want to display all hours and their counts for each date, will I have to use a listbox for dates and in that another listbox, with all hours and counts in that date?Can you show me how to do it?

  • 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-16T21:18:03+00:00Added an answer on May 16, 2026 at 9:18 pm

    Assuming you’re able to use LINQ, then you can do all the grouping and ordering in the C# fairly easily. (I’m assuming just a list of DateTime objects rather than full Show objects — it would appear you can get the DateTime for each Show with a simple LINQ Select statement.)

    var shows = new[]
                {
                    new DateTime(2010, 7, 28, 11, 15, 0),
                    new DateTime(2010, 7, 29, 8, 50, 0),
                    new DateTime(2010, 7, 29, 8, 55, 0)
                };
    
    var dates = shows.GroupBy(d => d.Date).OrderBy(d => d.Key);
    foreach (var date in dates)
    {
        Console.WriteLine("Date {0}", date.Key.ToShortDateString());
        var hours = date.GroupBy(d => d.Hour).OrderBy(d => d.Key);
        Console.WriteLine("\tHours\tCount");
        foreach (var hour in hours)
            Console.WriteLine("\t{0}-{1}\t{2}", hour.Key, (hour.Key+1)%24, hour.Count());
    }
    

    This provides the output:

    Date 7/28/2010
            Hours   Count
            11-12   1
    Date 7/29/2010
            Hours   Count
            8-9     2
    

    Note that this is just a simple Console Application example. You have not specified what GUI technology you are using (WinForms, WPF), so I’ll leave it as an exercise to take the grouping results and apply them in a GUI.

    Edit: Here is an example format in XAML using nested ItemsControls with DataBinding to a LINQ statement.

    <ItemsControl Name="ShowDates" ItemsSource="{Binding}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <HeaderedContentControl HeaderStringFormat="Date: {0}">
                <HeaderedContentControl.Header>
                    <StackPanel>
                        <TextBlock Text="{Binding Path=DateString, StringFormat='Date: {0}'}" />
                        <TextBlock Margin="20,1,1,1" Text="Hour : Shows"/>
                    </StackPanel>
                </HeaderedContentControl.Header>
                <ItemsControl Name="HoursList" Margin="20,1,1,1" ItemsSource="{Binding Path=Hours}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="{}{0}-{1} : {2}">
                                        <MultiBinding.Bindings>
                                            <Binding Path="HourStart" /> 
                                            <Binding Path="HourEnd" /> 
                                            <Binding Path="Count" /> 
                                        </MultiBinding.Bindings>
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </HeaderedContentControl>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    </ItemsControl>
    

    This uses a modified version of my original LINQ statement to make it easier for the DataBinding to be wired up. This code is in the constructor of my test Window.

        var result =
        shows
        .GroupBy(d => d.Date)
        .Select(gp => new{
            Date = gp.Key,
            DateString = gp.Key.ToShortDateString(),
            Hours = gp.GroupBy(d => d.Hour)
                        .Select(hgp => new {
                            HourStart = hgp.Key,
                            HourEnd = (hgp.Key + 1) % 24,
                            Count = hgp.Count()
                        })
                        .OrderBy(h => h.HourStart)
        });
    ShowDates.DataContext = result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.