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

Date Time and IFormatProvider

P: n/a
Hello All,
I am trying to bind a date in the form of "20031218" to a datetime
object. I first try to convert the string using
Convert.ToDateTime("20031218") but i get an invalid date time
exception. I think I should be using the IFormatProvider in one of the
overloaded methods of Convert.ToDateTime but i can't find any
documentation that is easy to understand.. i am a newbie if you will.
Any code examples of how to do this would be great.. this is what i
have so far.

case "System.Windows.Forms.DateTimePicker":
if (ctrl.Name == dt.TableName + dc.ToString())
{
DataRow dr = ds.Tables[dt.TableName].Rows[0];
if (dr[dc].Equals(""))
{
dr[dc] = DateTime.Today;
}
else
{
dr[dc] = Convert.ToDateTime(dr[dc]); //this is where the problem
lies
}
ctrl.DataBindings.Add(new Binding("Value",ds.Table[
dt.TableName],dc.ColumnName));
}
break;

Thanks in advance!!
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
XmlAdoNewbie <er************@cowaninsurancegroup.com> wrote:
I am trying to bind a date in the form of "20031218" to a datetime
object. I first try to convert the string using
Convert.ToDateTime("20031218") but i get an invalid date time
exception. I think I should be using the IFormatProvider in one of the
overloaded methods of Convert.ToDateTime but i can't find any
documentation that is easy to understand.. i am a newbie if you will.
Any code examples of how to do this would be great.. this is what i
have so far.


I suggest you use

DateTime.ParseExact (value, "yyyyMMdd", CultureInfo.InvariantCulture);

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

P: n/a
Thanks So Much Jon, that works like a charm!!

Erin
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.