Click here to Skip to main content
15,917,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I...i want to save only date not time in database from datetimepicker
Posted

use this code
C#
dateTimePicker1.Value.Date
note if you are using DateTime datatype in SQL datatabase it will be inserting default time value too it (ie. 2014-05-16 00:00:00)
 
Share this answer
 
Comments
tanugarg 16-May-14 6:51am    
thanks
Just you have maintain your database format in date only.

Date and Time Data Types:
DATA TYPE
datetime= YYYY-MM-DD hh:mm:ss[.nnn]
smalldatetime =YYYY-MM-DD hh:mm:ss
date = YYYY-MM-DD (Stores a date like June 30, 1991)

Get more details http://technet.microsoft.com/en-in/library/ms186724.aspx[^]
 
Share this answer
 
v3
cmd.CommandText = "INSERT INTO table (datefield) VALUES(@date)";
cmd.Parameters.Add(new SqlParameter("@date", dateTimePicker1.Value.Date));
 
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