Dataset WriteXML and XML dateTime

Hello All,

I have an issue when I write a dataset to an XML file.  I have a dateTime element and when it is written it writes out the full date and time including milliseconds.  I use the DateTime.Now to get the time value.  I want to write this without milliseconds.  Is this possible DateTime.Now when viewed as a string does not include the milliseconds but it does when it is written.

Any ideas

Regards,
Darren.



Answer this question

Dataset WriteXML and XML dateTime

  • butterflylion

    Thanks for the reply. I already looked at this workaround, as it was the only "solution" I could find too! I suppose I could use XMLConvert but it is a bit of a tacky solution.

    This is a really annoying "feature".

    Thanks for your help.

  • eastcowboy

    If you have a MyVar variable of type date, MyVar.ToString does not include milliseconds because the .net team decided that this would be a good way to turn a datetime to string. However a datetime variable contains the milliseconds information in it (try myVar.millisecond).

    So... the only thing you could do is somehow set the value to 0. It will still be writter in the xml file.

    Try this:

    Dim MyVar As Date = Now
            MyVar = MyVar.AddMilliseconds(-MyVar.Millisecond)

     



  • Dataset WriteXML and XML dateTime