Click here to Skip to main content
15,742,377 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi there,

I've a table in db consisting of a date column taking datetime datatype. Now I want to access this table from database on a button click which works on values from 2 textboxes (txtDateFrom & txtDateTill).
My database table has datetime datatype column so I also have to enter time in textboxes to get the required values.

I want to remove the time from datatype datetime or some other way, maybe using a different datatype (which I don't know) by which text boxes could take only date values and provide the table rows according to the information provided without writing time for each record.

Could someone help me with this...
Updated 12-Sep-10 21:50pm
Dalek Dave 13-Sep-10 3:50am    
Edited for Grammar and Readability.

1. It's not mandatory to pass on time while inserting a data in a DateTime column. By default it would pick 12:00:00 AM

2. You don't need a different datatype. Where ever you need to display the date, just format it in the desired format.
you can try: DateTime.Now.ToString("dd/MM/yyyy");

Have a look here [^]for various formats.
Share this answer
AmitChoudhary10 13-Sep-10 4:22am    
In my database table values records are stored like "MM/DD/YYYY 09:10:19:XX"
and i need to call the table by sending only dates in txtDateFrom(MM/DD/YYYY) to txtDateTill(MM/DD/YYYY) on a btn_click.without mentioning time can retrieve the table records?...
Sandeep Mewara 13-Sep-10 4:50am    
Looks like you are using a DateTime picker or directly a DateTime.Now in order to insert values.
If you want you can avoid sending time... but then SQL would put 12AM as default.

So better is ignore the time while retrieving in DB or in UI while showing. (show a defined format.)
AmitChoudhary10 13-Sep-10 4:56am    
I am not using a datepicker,dates are inputted in the txtbox

protected void btnGetOrderReport_Click(object sender, EventArgs e)
DataSet dsOrderReport = objSQLHelper.GetOrderReport(DateTime.Now.AddDays(-10), DateTime.Now);
gvOrderReport.DataSource = dsOrderReport;
gvOrderReport.Visible = true;

I am askin that in place of this
objSQLHelper.GetOrderReport(DateTime.Now.AddDays(-10), DateTime.Now);

can i write
objSQLHelper.GetOrderReport(txtbox1.txt, txtbox2.txt);

and if user does'nt put time after date,will it retrieve the table using datAdapter?..
Sandeep Mewara 13-Sep-10 5:49am    
you can write something like:
if(!String.IsNullOrEmtpy(txtbox1.txt) && !String.IsNullOrEmpty(txtbox2.txt))
objSQLHelper.GetOrderReport(Convert.ToInt32(txtbox1.txt), Convert.ToInt32(txtbox2.txt));
to solve that you would need to amend the sql to something like below


where CURRENT_TIMESTAMP will return the date and time in SQL Server

Convert codes more codes to use in the example above can be found in the remarks section of this article.
Share this answer
AmitChoudhary10 13-Sep-10 5:04am    
Thanks man...
Simon_Whale 13-Sep-10 5:40am    
your welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900