RanjitRock
RanjitRock

Reputation: 1451

how to categorise the given set of datetime in C#

I have a list of datetime values and i need to group them into hours base. something like

enter image description here

Upvotes: 0

Views: 56

Answers (2)

thumbmunkeys
thumbmunkeys

Reputation: 20764

You can use linq:

        var times = new List<DateTime>();

        var groups = times.GroupBy(date => (baseTime - date).TotalHours);

        foreach (var @group in groups)
        {
            Debug.WriteLine("hours: " + group.Key);
            foreach (var dateTime in group)
            {
                Debug.WriteLine(dateTime);
            }
        }

baseTime is the time from where you want to start off

Upvotes: 1

Albert Laure
Albert Laure

Reputation: 1722

You can convert Your time formats in 100 conversion

select convert(varchar, GetDate(), 100) as '100 Conversion'

Possible Result : Aug 27 2013 6:13PM Use string manipulation like substring to retrieve the number 6 and PM

Do some Logic to sort the retrieve Data.

after that your problem is done, Hope this Helps Thanks.

Upvotes: 0

Related Questions