Search code examples
windows-phone-7c#-4.0windows-phone-8datepicker

How to change the date from DD/MM/YYYY to YYYY-MM-DD using C#


I am using DatePicker to select the Date. So after selecting the date, I should display it through a MessageBox. I can able to display it but it is in the format DD/MM/YYYY.

And I want to display it in the format YYYY-MM-DD. So please can anyone help me to do the needful. Now I am displaying the date by using the code:

string date1 = datepicker.ValueString;
MessageBox.Show(date1);

But I can display the current date format and display it as required by using code:

string format = "yyyy-MM-dd";

string f = DateTime.Now.ToString(format);

So please help me to do the same by using DatePicker.


Solution

  • I did it by using code

    <toolkit:DatePicker Name="datepicker" BorderBrush="Transparent" BorderThickness="0" Value="" Background="Transparent" TabNavigation="Cycle" Template="{StaticResource DatePickerControlTemplate1}"/>
    

    and in CS file, I added

    string format = "yyyy-MM-dd";
            string date1 = datepicker.ValueString;
            DateTime datevalue = DateTime.Parse(date1);
            string d = datevalue.ToString(format);
            MessageBox.Show(d);
    

    and Lastly I got the required output and By the way for DatePicker we have to install WPtoolkit Package