Formatting Dates From XML file
-
I am reading an XML file into a dataset to be used by the Report Viewer control. Trouble is that I can't seem to format the date that is in the dataset. Here is what I'm trying. The date is the second column of the data table. private DataTable LoadData() { // Load data from XML file DataSet ds = new DataSet(); DataTable tbl; string myFilePath = (Application.StartupPath + "\\bin\\" + "trd.xml"); ds.ReadXml(myFilePath); tbl = ds.Tables[0]; foreach (DataRow row in tbl.Rows) { //reformat date row[1] = String.Format("{0:g}", row[1].ToString()); } return tbl; } Any help is greatly appreciated rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
I am reading an XML file into a dataset to be used by the Report Viewer control. Trouble is that I can't seem to format the date that is in the dataset. Here is what I'm trying. The date is the second column of the data table. private DataTable LoadData() { // Load data from XML file DataSet ds = new DataSet(); DataTable tbl; string myFilePath = (Application.StartupPath + "\\bin\\" + "trd.xml"); ds.ReadXml(myFilePath); tbl = ds.Tables[0]; foreach (DataRow row in tbl.Rows) { //reformat date row[1] = String.Format("{0:g}", row[1].ToString()); } return tbl; } Any help is greatly appreciated rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
Rafone wrote:
Trouble is that I can't seem to format the date that is in the dataset.
That's because you've failed to read the documentation[^] G is general. What you want is d for the short format or D for the long format.
I know the language. I've read a book. - _Madmatt
-
Rafone wrote:
Trouble is that I can't seem to format the date that is in the dataset.
That's because you've failed to read the documentation[^] G is general. What you want is d for the short format or D for the long format.
I know the language. I've read a book. - _Madmatt
Well having read the documentation numerous times it really does not mater how I format it the data row is not changing it remains with the formatting from the XML file (d) Short date: . . . . . . {0:d} is for just the date (g) General date/short time:. {0:g} is for the date and time the date in the XML is <DateTime>2009-11-07T08:10:00-07:00</DateTime> and remains even after trying to format it...? thx rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
Well having read the documentation numerous times it really does not mater how I format it the data row is not changing it remains with the formatting from the XML file (d) Short date: . . . . . . {0:d} is for just the date (g) General date/short time:. {0:g} is for the date and time the date in the XML is <DateTime>2009-11-07T08:10:00-07:00</DateTime> and remains even after trying to format it...? thx rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
You have to do a little more work, and understand the tools and language you are working with. XML stores everthing as a string, the d formatting option however expects to work with DateTime.
row[1] = String.Format("{0:d}", DateTime.Parse(row[1].ToString() ));
It isn't even ncessary to use String.Format
row[1] = DateTime.Parse(row[1].ToString()).ToShortDateString();
I know the language. I've read a book. - _Madmatt
-
Well having read the documentation numerous times it really does not mater how I format it the data row is not changing it remains with the formatting from the XML file (d) Short date: . . . . . . {0:d} is for just the date (g) General date/short time:. {0:g} is for the date and time the date in the XML is <DateTime>2009-11-07T08:10:00-07:00</DateTime> and remains even after trying to format it...? thx rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
You have to do a little more work, and understand the tools and language you are working with. XML stores everthing as a string, the d formatting option however expects to work with DateTime.
row[1] = String.Format("{0:d}", DateTime.Parse(row[1].ToString() ));
It isn't even ncessary to use String.Format
row[1] = DateTime.Parse(row[1].ToString()).ToShortDateString();
I know the language. I've read a book. - _Madmatt
-
I wish, I really wish, I had a pound (or even a rupee) for every question like this. Someone, somewhere, is breeding a generation of coders who do not have the remotest idea of what a DateTime is. Try reading the documentation once more.
-
Richard; Maybe we just don't have as much experience as some of you guys... THX for all feedback rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
Well having read the documentation numerous times it really does not mater how I format it the data row is not changing it remains with the formatting from the XML file (d) Short date: . . . . . . {0:d} is for just the date (g) General date/short time:. {0:g} is for the date and time the date in the XML is <DateTime>2009-11-07T08:10:00-07:00</DateTime> and remains even after trying to format it...? thx rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
(It's ISO 8601) Look at the
o
format.