stringnome
stringnome

Reputation: 233

radDateTimePicker best way to get and format the date value?

I need get the value of DateTimePicker component (like visual studio native DateTimePicker component, and basically the same thing) and turn it into a variable DateTime to execute a query in the Mysql database, the best way to play this value to see this format:

'2015-08-07'

 yyyy-mm-dd

Can anyone tell me how can I do this?

Upvotes: 0

Views: 717

Answers (2)

Scotty
Scotty

Reputation: 1137

Here's a Web Forms implementation...

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
}

Upvotes: 1

stringnome
stringnome

Reputation: 233

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);

Upvotes: 0

Related Questions