Bohrend
Bohrend

Reputation: 1497

Windows Phone 8 DateTime Formatting

I am trying to convert a date string to datetime. but it doesn't work, I know there are a few datetime posts on stackoverflow, however I couldn't come across the specific one I am having

     DateTime.ParseExact("22-07-2013", "dd-MMMM", CultureInfo.InvariantCulture)

I simply want to format the string to "22 Jul", but it gives me a system.format exception

am I missing something?

thanx

Upvotes: 0

Views: 914

Answers (2)

Kevin Gosse
Kevin Gosse

Reputation: 39007

The date you're trying to parse and the format you're using are inconsistent.

If you want to parse "22-07-2013" like shown in your example, use the format dd-MM-yyyy:

 DateTime.ParseExact("22-07-2013", "dd-MM-yyyy", CultureInfo.InvariantCulture)

If you want to parse "22 Jul" like you're saying in the question, use the format dd MMM:

 DateTime.ParseExact("22 Jul", "dd MMM", CultureInfo.InvariantCulture)

Upvotes: 3

Sandeep Chauhan
Sandeep Chauhan

Reputation: 1313

you can try this ....

                DatePicker date = new DatePicker();
                DateTime date1 = Convert.ToDateTime(date.ValueString);

Upvotes: 0

Related Questions