469,133 Members | 975 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

convert.ToDateTime vs System.DateTime.Parse

Is there any difference between convert.ToDateTime and
System.DateTime.Parse?

I am using them both and they seem the same.

Is one better to use than another?

Thanks,

Tom
Apr 20 '06 #1
4 34404
tshad <ts**********@ftsolutions.com> wrote:
Is there any difference between convert.ToDateTime and
System.DateTime.Parse?

I am using them both and they seem the same.

Is one better to use than another?


Convert.ToDateTime uses DateTime.Parse internally, with the current
culture - unless you pass it null, in which case it returns
DateTime.MinValue.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 20 '06 #2
Hi,

I bet one use the other, yep, according to MSDN Convert.ToDatetime use
DateTime.Parse. At least the overload method that receive a string.

and it seems that is the only one being used , all the other overloads of
Convert.ToDateTime says it throw an exception
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"tshad" <ts**********@ftsolutions.com> wrote in message
news:uf**************@TK2MSFTNGP05.phx.gbl...
Is there any difference between convert.ToDateTime and
System.DateTime.Parse?

I am using them both and they seem the same.

Is one better to use than another?

Thanks,

Tom

Apr 20 '06 #3
"tshad" <ts**********@ftsolutions.com> ha scritto nel messaggio
news:uf**************@TK2MSFTNGP05.phx.gbl...
Is there any difference between convert.ToDateTime and
System.DateTime.Parse?

I am using them both and they seem the same.

Is one better to use than another?


This is Convert.ToDateTime(string)

public static DateTime ToDateTime(string value)
{
if (value == null)
{
return new DateTime((long) 0);
}
return DateTime.Parse(value, CultureInfo.CurrentCulture);
}

And this is DateTime.Parse(string)

public static DateTime Parse(string s)
{
return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo,
DateTimeStyles.None);
}

That calls

internal static DateTime Parse(string s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
{
DateTimeResult result1 = new DateTimeResult();
result1.Init();
if (!DateTimeParse.TryParse(s, dtfi, styles, ref result1))
{
throw DateTimeParse.GetDateTimeParseException(ref result1);
}
return result1.parsedDate;
}
For details give it a look with Reflector.

--

Free .Net Reporting Tool - http://www.neodatatype.net
Apr 20 '06 #4
That what I wanted.

I can use either - just flip a coin :)

Thanks,

Tom
"Fabio" <zn*******@virgilio.it> wrote in message
news:el**************@TK2MSFTNGP04.phx.gbl...
"tshad" <ts**********@ftsolutions.com> ha scritto nel messaggio
news:uf**************@TK2MSFTNGP05.phx.gbl...
Is there any difference between convert.ToDateTime and
System.DateTime.Parse?

I am using them both and they seem the same.

Is one better to use than another?


This is Convert.ToDateTime(string)

public static DateTime ToDateTime(string value)
{
if (value == null)
{
return new DateTime((long) 0);
}
return DateTime.Parse(value, CultureInfo.CurrentCulture);
}

And this is DateTime.Parse(string)

public static DateTime Parse(string s)
{
return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo,
DateTimeStyles.None);
}

That calls

internal static DateTime Parse(string s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
{
DateTimeResult result1 = new DateTimeResult();
result1.Init();
if (!DateTimeParse.TryParse(s, dtfi, styles, ref result1))
{
throw DateTimeParse.GetDateTimeParseException(ref result1);
}
return result1.parsedDate;
}
For details give it a look with Reflector.

--

Free .Net Reporting Tool - http://www.neodatatype.net

Apr 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas Lindroos | last post: by
2 posts views Thread by Abhishek Srivastava | last post: by
2 posts views Thread by Franck | last post: by
5 posts views Thread by simon | last post: by
19 posts views Thread by simon | last post: by
2 posts views Thread by SimonZ | last post: by
5 posts views Thread by rsanan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.