locked
XMLWriter is taking Different Date Format RRS feed

  • Question

  • User-543160537 posted

    Hi,

    I am trying to genrate XML files out of excel file, I am using below code to generate XML but the date format it is showing in DataTable is different.

    var settings = new XmlWriterSettings();
                        settings.Indent = true;                   
                        settings.Encoding = Encoding.UTF8;
                        settings.OmitXmlDeclaration = true;             
                        var sb = new StringBuilder();
                        XmlWriter writer = XmlWriter.Create(sb, settings);
             
                            DataTable EventDetails = (from DataRow dr in SelectedRows.Rows
                                                      where dr["Event Id"].ToString() == item.ToString()
                                                      select dr).CopyToDataTable();
    
                            DateTime Sdate = (EventDetails.Rows[0]["StartDate"] == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(EventDetails.Rows[0]["StartDate"].ToString()));
                          
    

    Expected Output is : 6/19/2015

    Currently in EventDetails Datatable startdate item is showing as 42174.696527777778

    Please advice

    Thanks

    Sree

    Tuesday, September 29, 2015 11:13 AM

All replies

  • User-271186128 posted

    Hi Sree,

    Currently in EventDetails Datatable startdate item is showing as 42174.696527777778

    From your description, as we can see that the data is not date time type. I suggest you check the excel file and the EventDetails datatable, to make sure the start date item is date type first.

    Best regards,
    Dillion

    Wednesday, September 30, 2015 2:19 AM
  • User753101303 posted

    Hi,

    Try to call https://msdn.microsoft.com/en-us/library/system.datetime.fromoadate(v=vs.110).aspx on this value. Does it show the expected date?

    The issue is that Excel doesn't really hide that dates are actually stored as numbers and so if reading a value in Excel you may see a date while reading the same sheet with an ODBC driver etc... may show the actual underlying numeric value for this date.

    Wednesday, July 27, 2016 5:27 PM