Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Formatting Dates From XML file

Formatting Dates From XML file

Scheduled Pinned Locked Moved C#
xmlhelp
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rafone
    wrote on last edited by
    #1

    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 ...

    N 1 Reply Last reply
    0
    • R Rafone

      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 ...

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • N Not Active

        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

        R Offline
        R Offline
        Rafone
        wrote on last edited by
        #3

        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 ...

        N L P 3 Replies Last reply
        0
        • R Rafone

          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 ...

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • R Rafone

            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 ...

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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.

            R 1 Reply Last reply
            0
            • N Not Active

              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

              R Offline
              R Offline
              Rafone
              wrote on last edited by
              #6

              THX Mark that did the trick and turned on the lights thx rafone

              Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...

              1 Reply Last reply
              0
              • L Lost User

                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.

                R Offline
                R Offline
                Rafone
                wrote on last edited by
                #7

                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 ...

                L 1 Reply Last reply
                0
                • R Rafone

                  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 ...

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Rafone wrote:

                  Maybe we just don't have as much experience as some of you guys...

                  Maybe you don't spend enough time reading the documentation first!

                  1 Reply Last reply
                  0
                  • R Rafone

                    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 ...

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    (It's ISO 8601) Look at the o format.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups