Hi
 
I spent some time playing with the datetime parse functions, and found that this works best for me... might help you out.
 

string[] expectedFormats = {"dd MMM yyyy HH:mm:ss:fff", "dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss", "dd/MM/yyyy HH:mm", "dd MMM yyyy HH:mm", "dd MMM yyyy HH:mm:ss"};

DateTime dt = DateTime.ParseExact( "02/06/2004",expectedFormats, null, DateTimeStyles.None);

I think if you don't supply the expected formats it uses the default ones for your current locale.

HTH

 

Matt



From: Deepak Mazumdar [mailto:[EMAIL PROTECTED]
Sent: 01 November 2004 10:10
To: [EMAIL PROTECTED]
Subject: RE: [Microsofts_C_Sharp] How to assign String value to date.
Importance: High

Do like this

String[] tmp = datevariable.Split("/")

DateTime newDate = new DateTime(tmp[0], tmp[1], tmp[2])

newDate will be u r new date.



-----Original Message-----
From: mohanraj [mailto:[EMAIL PROTECTED]
Sent: 01 November 2004 11:43 AM
To: [EMAIL PROTECTED]
Subject: [Microsofts_C_Sharp] How to assign String value to date.




HI :

 
  How to convert string to Date Value..

      here this is code
      System.DateTime dt = new System.DateTime ();
      dt = System.DateTime.ParseExact("02/06/2004");

  when i try to convert iam getting following Error.

   System.FormatException: String was not recognized as a valid
DateTime.


Regards,

J. Mohanraj






Yahoo! Groups Links









Yahoo! Groups Sponsor

Get unlimited calls to

U.S./Canada



Yahoo! Groups Links

Reply via email to