The below code (in C#) will help us to Display and Read Value from DatePicker in dd.yyyy.mm.
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string @format = "dd.yyyy.MM"; //date format
public Form1()
{
InitializeComponent();
}
//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)
{
MessageBox.Show(dateTimePicker1.Value.Date.ToString(@format));
}
}
}
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.
ToString(@format)