Click here to Skip to main content
15,909,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a text field with name yearTextfield i m using datepicker and populate the text field with date picker value.can any one tell me how i format the date so that i could save it in db.the value comes in text field is like this format 25-05-2011 plz help me thanks in advance
Posted

Check this link[^] out.

That[^] might also work.

Good luck.
 
Share this answer
 
Comments
waqasahmed786 13-May-11 18:37pm    
i am using this
string format ="dd/MM/yyyy";
qualification.YearOfPassing=DateTime.ParseExact(YearTextBox.Text.ToString(), format, null);

i got exception of incorrect format plz help me in this regards
Orcun Iyigun 13-May-11 19:17pm    
As fcronin said ;The field in database is a date field or varchar?

try => string MyDateTimeStr = dateTimePicker1.Value.ToString(format);
If you want the month first, get it's value as a string like this...

dateTimePicker1.Value.ToString("MM-dd-yyyy");

What format you need it in depends somewhat on how you're putting in your database.

Hope that helps.
 
Share this answer
 
If you what to save a DateTime in Sql. Then do a datetime1.ToString("s")[^] it is a Sortable DateTime Pattern.

Showing a DateTime in UI is NOT the same as saving it in a database. When you do a datetime1.ToString(), .ToString() will use current Culture settings to show the value for the use.
 
Share this answer
 
v2

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