Hi everyone,

Can I ask your suggestion? Please..

I got the problem in my query, about storing the Date into my database. When time I submit o saved the data inputed to my textfield , the query is okay, but when I checked the database the date it's not good(the date look like this '1/10/14 12:00:00' with time. in my C# form i customize the timepicker, I set to "Custom" w/o the time, in my database I set the Type to "DATE". I want time not include to save in the DB.

Can everyone help me?

the code that I sued:

 public void SetMyCustomFormat()
        {
            // Set the Format type and the CustomFormat string.

            timepicker_im.Format = DateTimePickerFormat.Custom;
            timepicker_im.CustomFormat = "yy-MM-dd";
        }

Regards,

Darry

It's still the same Date and time that is saved into the database. So when you return the value from the database you can specify the format you need as you did above.

When saving the value to the database use the following.

dateTimePicker1.Value.ToString()
dateTimePicker1.Value.ToShortDateString()

I am sure Fenrir() is absolutely correct for dateTimePicker1.Value.ToShortDateString() as it will trim out the time that is coming into your table present in some database :)

I tried the code but it's the same result.

String idnumber, payment, fname, mname, lname, email, cnumber, expertise, country, address, pidate, status;

                idnumber = PD_Idnumber.Text;
                payment = comboBox1.Text;
                fname = textBox2.Text;
                mname = textBox3.Text;
                lname = textBox4.Text;
                email = textBox5.Text;
                cnumber = textBox6.Text;
                expertise = expert_im.Text;
                country = country_im.Text;
                address = textBox7.Text;
                pidate = timepicker_im.Value.ToString();
                status = comboBox2.Text;

                OpenConCls.nonQuery("INSERT INTO tblpair_individual_membership values('" + idnumber + "','" + fname + "','" + mname + "','" + lname + "','" + email + "','" + cnumber + "','" + expertise + "','" + country + "','" + address + "','" + payment + "','" + status + "','" + timepicker_im.Value.ToString() + "')");
                MessageBox.Show("Succesfully Save");

and the Output : 1/1/0001 12:00:00 AM

regards,
Darryl

I don't see you using timepicker_im.Value.ToShortDateString(); ?

Instead of pidate = timepicker_im.Value.ToString(); write as pidate = timepicker_im.Value.ToShortDateString().

And also, instead of

OpenConCls.nonQuery("INSERT INTO tblpair_individual_membership values('" + idnumber + "','" + fname + "','" + mname + "','" + lname + "','" + email + "','" + cnumber + "','" + expertise + "','" + country + "','" + address + "','" + payment + "','" + status + "','" + timepicker_im.Value.ToString() + "')");

write the following :-

OpenConCls.nonQuery("INSERT INTO tblpair_individual_membership values('" + idnumber + "','" + fname + "','" + mname + "','" + lname + "','" + email + "','" + cnumber + "','" + expertise + "','" + country + "','" + address + "','" + payment + "','" + status + "','" + pidate + "')");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.