By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,460 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,460 IT Pros & Developers. It's quick & easy.

string to DateTime

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

Tnx, Alejandro.

Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Try the DateTime.ParseExact() method.

--
Tim Wilson
..Net Compact Framework MVP

"Alejandro Penate-Diaz" <al********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
how can I convert a string like this "10/00" meaning octuber/2000 to a valid DateTime?

Tnx, Alejandro.

Nov 16 '05 #2

P: n/a
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

"Alejandro Penate-Diaz" wrote:
how can I convert a string like this "10/00" meaning octuber/2000 to a valid
DateTime?

Tnx, Alejandro.

Nov 16 '05 #3

P: n/a
Thanks, that's exactly what I was planning to do.
"dlgproc" <dl*****@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
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

"Alejandro Penate-Diaz" wrote:
how can I convert a string like this "10/00" meaning octuber/2000 to a
valid
DateTime?

Tnx, Alejandro.

Nov 16 '05 #4

P: n/a
Hi,

try DateTime.ParseExact.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Alejandro Penate-Diaz" <al********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
how can I convert a string like this "10/00" meaning octuber/2000 to a
valid
DateTime?

Tnx, Alejandro.

Nov 16 '05 #5

P: n/a
Ignacio Machin from UH?
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

try DateTime.ParseExact.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Alejandro Penate-Diaz" <al********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
how can I convert a string like this "10/00" meaning octuber/2000 to a
valid
DateTime?

Tnx, Alejandro.


Nov 16 '05 #6

P: n/a
dlgproc <dl*****@discussions.microsoft.com> wrote:
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);
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.