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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:03:40+00:00 2026-06-08T01:03:40+00:00

I have a DataTable dt with two columns FromDate and ToDate . I have

  • 0

I have a DataTable dt with two columns FromDate and ToDate. I have two textboxes where I am entering the dates blackOutFromDate and blackOutToDate. Say, I have 7 rows inside my DataTable dt:

From Date       To Date      
8/21/2012   To  8/22/2012   
8/23/2012   To  8/24/2012   
8/25/2012   To  8/25/2012   
8/5/2012    To  8/6/2012    
8/26/2012   To  8/27/2012   
8/1/2012    To  8/2/2012    
8/3/2012    To  8/3/2012

If the value that I enter inside my text boxes CheckInDate and CheckOutDate is between any matching date range of DataTable dt, it should return the count of the noumber of rows having such match.

I am doing

foundRows = _blackOutTable.Select
                               (
                                   "(FromDate <='" +     
blackOutFromDate.ToShortDateString() + "' AND ToDate >= '" + 
blackOutFromDate.ToShortDateString() + "')"
                                   + "OR (FromDate <='" + 
blackOutToDate.ToShortDateString() + "' AND ToDate >='" + 
blackOutToDate.ToShortDateString() + "')"
                                   + "OR (FromDate >='" + 
blackOutFromDate.ToShortDateString() + "' AND FromDate <='" +     
blackOutToDate.ToShortDateString() + "')"
                                   + "OR (ToDate >= '" +   
blackOutFromDate.ToShortDateString() + "' AND ToDate <='" +     
blackOutToDate.ToShortDateString() + "')"
                               );
if (foundRows.Length == 0)
{
}

EDIT :
I am storing the DateFrom and DateTo filed inside SQl Server as

CAST(MONTH(date1) AS VARCHAR(2)) + '/' + CAST(DAY(date1) AS VARCHAR(2)) + '/' +     
CAST(YEAR(date1) AS VARCHAR(4))  [fromdate],
        CAST(MONTH(date2) AS VARCHAR(2)) + '/' + CAST(DAY(date2) AS 
VARCHAR(2)) + '/' + CAST(YEAR(date2) AS VARCHAR(4))  [todate]

blackOutFromDate and blackOutFromDate are of DateTime types.

But it’s not returning the correct values. There is some problem with the select expression. What can I do to fix this?

  • 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-08T01:03:42+00:00Added an answer on June 8, 2026 at 1:03 am

    This is the DataTable.Select syntax for DateTimes:

    foundRows = _blackOutTable.Select("FromDate >= #2012-07-13#")
    

    So you need to use String.Format to put your date variable into that string.

    Edit: Since your datetimes are converted to varchar and you cannot change that, you need to parse them back to datetime. I would recommend to use Linq-To-DataSet:

    DataTable tblFiltered;
    var invCulture=System.Globalization.CultureInfo.InvariantCulture;
    var filteredRows = _blackOutTable.AsEnumerable()
        .Where(r => DateTime.Parse(r.Field<String>("FromDate"), invCulture) >= blackOutFromDate
                 && DateTime.Parse(r.Field<String>("ToDate"),   invCulture) <= blackOutToDate);
    
    if (filteredRows.Any())
    {
        tblFiltered = filteredRows.CopyToDataTable();
    }
    

    You can use foreach to enumerate all rows or use CopyToDataTable to create a new DataTable from the filtered DataRows.

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

Sidebar

Related Questions

I have a datatable with two columns FromDate and ToDate , which are in
I have a datatable with two columns. I want to store the rows of
I have a datatable with two columns, Column 1 = EmpID Column 2 =
I'm using Visual Studio 2005 and have a DataTable with two columns and some
I have two DataTables. First is DataTable NameAddressPhones = new DataTable(); with Three columns
we have a datatable st with two columns word and binary void replace() {
I have two datatable , first contain DataTable dtMaterialStatement = new DataTable(); dtMaterialStatement.Columns.Add(new DataColumn(MaterialNo,
I have a datatable containing 10 columns. I want to select only two columns
I have asp:datalist binding from table this table contain two columns one of them
I have DataTable with two columns Author and Bookname . I want to check

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.