string to DateTime

  • Thread starter Thread starter Alejandro Penate-Diaz
  • Start date Start date
A

Alejandro Penate-Diaz

how can I convert a string like this "10/00" meaning octuber/2000 to a valid
DateTime?

Tnx, Alejandro.
 
I could be wrong, but I don't think you can since a valid DateTime must have
a Month, Day and Year. Try specifying a 1 for the day but not using when you
display it.

String cStr = “10/1/00â€;
DateTime oDT = DateTime.Parse(cStr);

Hope this helps.
Regards
 
dlgproc said:
I could be wrong, but I don't think you can since a valid DateTime must have
a Month, Day and Year.

Fields which aren't specified are defaulted. Try the following program:

using System;
using System.Globalization;

class Test
{
static void Main()
{
DateTime dt = DateTime.ParseExact("10/00", "MM'/'yy",
CultureInfo.InvariantCulture);
Console.WriteLine (dt);
}
}
 
Back
Top