radDateTimePicker 获取和格式化日期值的最佳方式?

radDateTimePicker best way to get and format the date value?

我需要获取 DateTimePicker 组件的值(就像 visual studio 原生 DateTimePicker 组件,基本上是一样的)并将其转换为变量 DateTime 以在Mysql数据库中执行查询,打这个值最好看这个格式:

'2015-08-07'

 yyyy-mm-dd

谁能告诉我该怎么做?

private DateTime InitialDate;
private DateTime EndDate;


this.dataInicial = new DateTime(radDateTimePickerInitialDate.Value.Year, radDateTimePickerInitialDate.Value.Month, radDateTimePickerInitialDate.Value.Day);
this.dataFinal   = new DateTime(radDateTimePickerEndDate.Value.Year, radDateTimePickerEndDate.Value.Month, radDateTimePickerEndDate.Value.Day);

这是一个 Web 窗体实现...

protected void btnMyButton_Click(object sender, EventArgs e)
{
    if (!Page.IsValid) return; // Handle rdpMyDateTimePicker not having a selected date by using a RequiredFieldValidator control
    if (rdpMyDateTimePicker.SelectedDate == null) return; // Proper form validation should always prevent this being null

    var formattedDate = Convert.ToDateTime(rdpMyDateTimePicker.SelectedDate).ToString("yyyy-MM-dd");

    // Now insert the formattedDate string as a parameter into your database query
}