To Display and Read Value from DatePicker in (C# code)

Posted by Rajnilari2015 under Windows Forms category on | Points: 40 | Views : 2868
The below code (in C#) will help us to Display and Read Value from DatePicker in

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
public partial class Form1 : Form
string @format = "dd.yyyy.MM"; //date format
public Form1()

//set the datepicker display format at form load time
private void Form1_Load(object sender, EventArgs e)
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = @format;


//read the datepicker value of the given format on button click
private void button1_Click(object sender, EventArgs e)

For setting the datetime-picker value, we are using

a) Format Property : Gets or sets the format of the date and time displayed in the control.
b) CustomFormat Property : Gets or sets the custom date/time format string.

For reading the value from the datetime-picker, we are formatting the ToString() e.g.

Comments or Responses

Login to post response