string to DateTime

  • Thread starter Alejandro Penate-Diaz
  • 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.
 
G

Guest

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
 
J

Jon Skeet [C# MVP]

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top