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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:29:50+00:00 2026-06-09T21:29:50+00:00

I have a datatable that has many fields from many event files. I need

  • 0

I have a datatable that has many fields from many event files. I need to be able to select distinct on the time. The datetime field is in this format MM/dd/yyyy HH:mm:ss .. I am trying this:

dpall = RollUpValuesFunctions.jobTableFinalCSVOutput.DefaultView.ToTable();

what I am wondering is if there is a way to apply a constraint on the datetime field to only get a distinct date like MM/dd/yyyy HH:mm?
Each minute has a couple hundred records, but for my purposes I only need one of the records from that minute.

And this is in C#

  • 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-09T21:29:52+00:00Added an answer on June 9, 2026 at 9:29 pm

    Given the following data:

    var dt = new DataTable();
    dt.Columns.Add(new DataColumn("Time", typeof(DateTime)));
    dt.Rows.Add(new DateTime(2000, 12, 31, 12, 0, 0));
    dt.Rows.Add(new DateTime(2000, 12, 31, 12, 0, 0));
    dt.Rows.Add(new DateTime(2000, 12, 31, 12, 0, 1));
    dt.Rows.Add(new DateTime(2000, 12, 31, 12, 0, 2));
    dt.Rows.Add(new DateTime(2000, 12, 31, 12, 4, 2));
    dt.Rows.Add(new DateTime(2000, 12, 31, 12, 5, 5));
    dt.Rows.Add(new DateTime(2000, 12, 31, 12, 5, 2));
    

    the obvoius Linq approach is

    var result = from row in dt.AsEnumerable()
                 let d = row.Field<DateTime>("Time")
                 group row by new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 0) into g
                 select g.First();
    
    foreach (DataRow row in result)
        Console.WriteLine(row["Time"]);   
    

    but since you asked for a non-linq solution, why not just iterate over each row, get rid of the seconds part of the time, and use a DataView to do the Distinct part:

    foreach (DataRow row in dt.Rows)
    {
        DateTime d = row.Field<DateTime>("Time");
        row["Time"] = new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 0);
        // or use "tricks" like this
        // row["Time"] = d.AddTicks(-(d.Ticks % TimeSpan.TicksPerMinute));
    }
    
    foreach(DataRow r in new DataView(dt).ToTable(true).Rows)
        Console.WriteLine(r["Time"]);
    

    If you don’t want to change your DataTable, you can copy it before.

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

Sidebar

Related Questions

I have a datatable that has many NULL or strings. Next I am type
I have a DataTable that has a boolean column called [Invalid]. I need to
I have a simple Parallel.Foreach loop that has about 1000 rows in the DataTable,
Lets say you have a DataTable that has columns of id, cost, qty: DataTable
I have a huge form that has around 110 fields columns (single row) that
I have a DataTable that has several DataColumns and DataRow. Now i would like
I have a datatable with some rows I need to insert that datatable in
I have a DataTable that has a date broken up by Month & Year.
I have a datatable that has duplicate ID's. 1 data moredata 4354 1 data
I have a datatable that has a date column, but I am stumped as

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.