473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 35826
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Lindroos | last post by:
how to convert this??? string strDate = "19701105"; DateTime myDate = System.Convert.ToDateTime(strDate); ideas anyone /thomas lindroos
2
by: Abhishek Srivastava | last post by:
Hello All, I wrote the following program. using System; using System.Globalization; public class ShortDateTest { public static void Main(string args)
2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
5
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
19
by: simon | last post by:
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM" Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error...
2
by: SimonZ | last post by:
Hi, can someone explain me, when to use: (DateTime)DataBinder.Eval(Container.DataItem, "dateField") OR Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "dateField")) Sometimes...
5
by: rsanan | last post by:
How do I convert a datetime from en-GB to en-US format here is my code - (not working for the clients outside of US) /*******************CODE*****************/ System.Globalization.CultureInfo...
14
by: Me | last post by:
Hi all I am getting a really bizzare error on when I convert a string into a datetime: The code is : DateTime dt1 = Convert.ToDateTime("10 Sep 2005"); Console.WriteLine(dt1.Year);
9
by: mcfly1204 | last post by:
I have read through various posts on converting a string into the datetime format, but cannot resolve my situation. I have a string in the format of 'yyyymmddthhmmss.sssz' that I would like to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.