Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have datetimepicker on form

i need date stored in database in this manner --2013-01-22 00:00:00.000

but when user make the entry it save like--2013-01-21 14:58:00.000

How can i resolved this issue??
Posted
Comments
Richard MacCutchan 22-Jan-13 5:01am    
Do not store dates as text. SQL has a DateTime type specifically for storing such values.
Master Vinu 22-Jan-13 5:03am    
yer dear i have taken datatype-- datetime in sql
Master Vinu 22-Jan-13 5:08am    
cmd.Parameters.AddWithValue("Date", dateTimePicker1.Value.ToString());

Cast your datetime variable with ToShortDateString so you can eliminate the time part from your datetime varible.

Please let me know if you are looking for this.

Happy Programming
:)
 
Share this answer
 
Try this....
C#
DateTime dt = new DateTime();
          string lstrDate = "2013-01-21 14:58:00.000";
          dt = Convert.ToDateTime(lstrDate);
          string lstrADate = dt.ToString("yyyy-MM-dd");


Use lstrAData variable value to store in the database...
 
Share this answer
 
v2
HI,

Use the following link for parsing and formating any date format.

Different date formats

Thanks
 
Share this answer
 

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