user1656695
user1656695

Reputation: 3

customizing datetimepicker

I'm making a program using C# vs2008, this is a preparation for my thesis. I'm trying to make my date time picker to show month/day/year without the time in my datagridview. My date time picker is set into datetime.

Here's the sample of my code:

Registrar.InsertStudent(
        Convert.ToInt32(txtStud_ID.Text), 
        txtFname.Text, 
        txtGname.Text,
        txtMname.Text, 
        txtPAdd.Text, 
        txtLline.Text,
        txtMobile.Text, 
        cbCitizen.SelectedItem.ToString(), 
        dtpDOB.Value,
        Convert.ToInt32(txtAge.Text), 
        cbGradeLvL.SelectedItem.ToString(), 
        cbGender.SelectedItem.ToString(),
        txtMotherName.Text, 
        txtMComp.Text, 
        txtMOcc.Text, 
        txtMAdd.Text,
        txtMTele.Text, 
        txtFatherName.Text, 
        txtFComp.Text, 
        txtFOcc.Text,
        txtFAdd.Text, 
        txtFTele.Text, 
        Convert.ToInt32(txtSiblings.Text),
        txtSchool_Last_Attend.Text, 
        txtSchool_Add.Text, 
        txtDname.Text,
        txtDTele.Text, 
        txtInsuComp.Text, 
        cbMedical_List.SelectedItem.ToString(),
        txtPerson_Notified.Text, 
        cbRelation_Pupil.SelectedItem.ToString(), 
        txtIE_Contact.Text,
        txtOther_Allergy.Text, 
        txtOtherIE.Text
        );

Upvotes: 0

Views: 315

Answers (3)

Siva Sankar Gorantla
Siva Sankar Gorantla

Reputation: 562

You can set custom date format to the DateTimePicker as follows:

this.datetimepicker.Format = DateTimePickerFormat.Custom;
this.datetimepicker.CustomFormat = "MM-dd-yyyy"

Upvotes: 1

user1378730
user1378730

Reputation: 930

Don't fully understand your question but if you can access the DateTime variable.

DateTime dt = DateTime.Now;
string dateString = dt.ToString("yyyy-mm-dd");

dateString now equals = "2012-09-08" (depending on timezone)

Upvotes: 0

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

You can try with this code

var result = dateTimePicker1.Value.Date.ToString();

Upvotes: 0

Related Questions