tags:

views:

82

answers:

4

hi

i get date from xml in this format: 7/16/2010 (mm/dd/yyyy)

i have in my program datetime val - MyDate.

and when i try to placing MyDate = Convert.ToDateTime(7/16/2010)

i got error.

how i can fix it ?

thank's in advance

A: 

do you need to delimit your date with double-quotes?

MyDate = Convert.ToDateTime("7/16/2010")

as it's converting from string?

Beth
+2  A: 
DateTime MyDate = DateTime.ParseExact("7/16/2010", "M/dd/yyyy", CultureInfo.InvariantCulture);
Forgotten Semicolon
Be aware that the caller might want the current culture not culture invariant.
Doug
@Doug, not when that date format is specified. ;-)
Forgotten Semicolon
My point was that you are making an assumption.
Doug
A: 

Hi,

DateTime.Parse("7/16/2010");

Here is a link to the DateTime.Parse documentation.

Enjoy!

Doug
Be careful. DateTime.Parse relies on the CurrentCulture.
Forgotten Semicolon
A: 

MyDate = #7/16/2010#
but first you have to switch to VB ;-)

FastAl