473,320 Members | 1,991 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,320 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 35801
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.