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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:08:30+00:00 2026-06-15T00:08:30+00:00

Updated: I am trying to filter a DataTable based on a particular date. My

  • 0

Updated:

I am trying to filter a DataTable based on a particular date.
My datatable has a column “whn” which contains dates. A Sample date from the DataTable:

{21/02/2012 10:03:53}   object {System.DateTime}

Here is the code I am using to try and filter the DataTable:

 String datevalue= "21/02/2012 10:03:53";

  DataRow[] foundRows;
  foundRows = dttemp.Select(String.Format("whn = '{0}'", datevalue));

However this does not work and returns 0 rows. Even though I know that a row containing the date in “datevalue” exists.

Unsure why this is not working, any help is appreciated.

Thanks.

  • 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-15T00:08:32+00:00Added an answer on June 15, 2026 at 12:08 am

    If you want to exactly match the supplied DateTime, including fractions of a second, you should use a DateTime format that has enough precision. Probably the round-trip format (“o”) is a good bet:

    foundRows = dttemp.Select(String.Format(dttemp.Locale, "whn = '{0:o}'", datevalue));
    

    However, it’s more likely you want to match values that fall into a range. For example, if you want all values that have the same date, but any time of day, you could use:

    foundRows = dttemp.Select(String.Format(dttemp.Locale, "whn >='{0:o}' AND whn < '{1:o}'",
          datevalue.Date, datevalue.AddDays(1).Date));
    

    Similarly if you want all values that are in the same second (but may have fractions of a second), you can use:

    DateTime from = dttemp.AddTicks( - (dttemp.Ticks % TimeSpan.TicksPerSecond));
    foundRows = dttemp.Select(String.Format(dttemp.Locale, "whn >='{0:o}' AND whn < '{1:o}'",
          from, from.AddSeconds(1)));
    

    The call to AddTicks truncates the supplied DateTime to a whole number of seconds, as described in the accepted answer to this StackOverflow question.

    Note I used dttemp.Locale to use the correct locale (CultureInfo) in case your DataTable has a locale other than your current culture.

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

Sidebar

Related Questions

I am trying to use a SqlDataAdapter to fill a DataTable , which I
I am trying to filter out invalid url from valid ones using .NET. I
I'm trying to filter my orders which are returned back by the magento API
I'm trying to add a content_save_pre filter to update a custom field based on
I'm trying to display html text received from the server in a datatable row.
following is my sql query in which i am trying to filter the result
I am trying to upload an updated version of my application (.apk) in google
I'm trying to show updated results for a CCK Computed Field. The computation is
I'm trying to get an updated version for Windows vista. I previously got 21.4.22
I am trying to get all users that are updated maximum 90 seconds ago:

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.