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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:29:28+00:00 2026-05-27T02:29:28+00:00

I have a records in my table Test like this my Date column is

  • 0

I have a records in my table Test like this my Date column is of type varchar.

Fname      Lname      Date  
vivek      parikh     01-09-2011 10:00:00 PM  
kashyap    vyas       02-09-2011 10:50:00 AM  
viral      panchal    02-09-2011 10:00:00 PM  
Arpit      Gosai      03-09-2011 10:00:00 PM  
Darshit    Chokshi    04-09-2011 10:00:00 PM  
Sameer     Rangrez    24-08-2011 9:15:12 AM  

i want to fetch records within date range (start date and end date) from page.

my code is

 DateTime time = DateTime.Today;             // Use current time
    string format = "MM-dd-yyyy";

    SqlCommand cmd = new SqlCommand("select Fname,Lname,Insert_Date from Test where Insert_Date >= '" + Convert.ToDateTime(TextBox1.Text).ToString(format) + "' and Insert_Date <= '" + Convert.ToDateTime(TextBox2.Text).ToString(format) + "'  ", con);
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);

    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
    {
        Response.Write(ds.Tables[0].Rows[i]["Fname"].ToString());
        Response.Write(ds.Tables[0].Rows[i]["Lname"].ToString());
        Response.Write(ds.Tables[0].Rows[i]["Insert_Date"].ToString()+"<br>");
    }
  • 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-27T02:29:29+00:00Added an answer on May 27, 2026 at 2:29 am

    for building your query use Convert(datetime,fieldname,103) for converting varchar to datetime.

    Your query should be something like.

    select * from Test
    where Convert(datetime,field_date,103) >= ‘2011-01-01’ –start date

    and Convert(datetime,field_date,103) <= ‘2012-01-01’; –end date

    This is how your C# statement should look like (It should include 103 code to specify your date format which dd-mm-yyyy

     SqlCommand cmd = new SqlCommand("select Fname,Lname,Insert_Date from Test where Convert(datetime,Insert_Date,103) >= '" + Convert.ToDateTime(TextBox1.Text).ToString(format) + "' and Convert(datetime,Insert_Date,103) <= '" + Convert.ToDateTime(TextBox2.Text).ToString(format) + "'  ", con);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MySQL 5 I have a table like this: date (varchar) door (varchar) shift
I have a table like this and type is innodb and id and sid
I have a table that simplified looks like this: create table Test ( ValidFrom
(Using Oracle) I have a table with key/value pairs like this: create table MESSAGE_INDEX
I have this database which contains a varchar. I want to know which records
I have a table like: ID word masterWord 1 test 1 1 test1 0
I have a table that have two fields. table test { fname char(20), id
I have two tables like Parent-Child. In Parent table, there are 7211 records. In
I have this table with this columns: Key,Type,Culture. Key and Culture are PK. I
I have three records in a table example: *Usernames* *email* *city* Nick nick@example.com London

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.