473,407 Members | 2,320 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,407 software developers and data experts.

Date Time and IFormatProvider

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
2 27672
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
Thanks So Much Jon, that works like a charm!!

Erin
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
5
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from...
6
by: Mark Reed | last post by:
Hi Guru's, I have created a database to monitor hours I have worked as our payroll department are so crap. I work nights most of the time but occasionally I have to work on days. Between the hours...
9
by: Shapper | last post by:
Hello, I created a dataset from a XML file. One of the dataset fields is . In an ASP:Repeater I am displaying the field. <%# DataBinder.Eval(Container.DataItem, "pubDate", "{0:f}") %> The...
2
by: XmlAdoNewbie | last post by:
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...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
4
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
4
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.