Click here to Skip to main content
16,008,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

I have windows form.and also it has database.I'm entering data "productT" table of that database.
That table has 7 fields.

these are essential fields

field name datatype

MFDdate datetime

EXPdate datetime

I want add only date to the above fields using datetimepicker.I used 2 datetimepickers.

Here is the code I tried.

C#
dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "yyyy-MM-dd";
            dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            dateTimePicker2.CustomFormat = "yyyy-MM-dd";

SqlCommand comm1 = new SqlCommand("INSERT INTO productT(MFDdate,EXPdate)Values('" +dateTimePicker1.Value.Date+"','" +dateTimePicker2.Value.Date+ "')", conn1);


I looking for answers.This is really annoying problem.

please help me
Posted
Updated 11-Oct-13 6:15am
v3
Comments
Ron Beyer 11-Oct-13 12:26pm    
What is the type of the MFdate and EXPdate columns? If its DateTime it will always have a time, no matter what you do.
Ron Beyer 11-Oct-13 12:29pm    
I answered below, this is pretty cut and dry.

MFdate and EXPdate are Datetime columns.

That means they will always have a time in them. If you just want to use the date part, wherever you are displaying it you need to format the DateTime so that it includes just the date portion, but the SQL will contain a time, you can't change that.
 
Share this answer
 
Comments
sachinthasri 12-Oct-13 0:32am    
if I use MFD,EXP dates in SQL database as text.
Where should I change the code?.Can I change the datetimepicker values "ToShortDateString();"
C#
string transactionDate = drForTransInfo[8].ToString();
                        string getDate = string[] dateSplit = transactionDate.Split(' ');
                        foreach (string word in dateSplit)
                        {
                            getDate = dateSplit[0].onvert.ToDateTime(drForTransInfo[9].ToString()).ToString("hh:mm:ss tt");
                        }
                        lblDate.Text = getDate;
 
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