Hi frnds,
i have make a form in asp.net there is an date textbox from which date and time is passing.
i only want to pass the date in database from the aspx Form not the default time.
need ur help
Thanks
Aaamir
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pravin GhadgePosted Sep 30, 2011, 4:05 AM
At time of saving date in database u have to convert the date into shortdatestring().
For eg:Convert.Datetime(txtDate.Text).ToshortDateString();
Thanks
Prabhu RajaPosted Sep 30, 2011, 5:10 AM
Why we are using TryParse() means, it will solve Null Reference Error. Consider, this method.
Convert.DateTime(txtBoxDate.Text.Trim()).ToShortDateString();
What Will Happen, if the textBox is Empty. It will result in error. So, I suggeset you to use TryParse() Method.
Example :
DateTime dateValue = new DateTime();
Bool isConverted = DateTime.TryParse(txtBoxDate.Text.Trim(), out dateValue);
if (isConverted)
{
//use Your Date as
dateValue.ToShortDateString();
}
else
{
// Show Message to User, for Selection of Date
}
Thank You
Pravin MorePosted Sep 30, 2011, 4:45 AM
Try This..........
DateTime dtval= textBox1.Text;
dtval=dtval.Date;
This will help.
Thanx.