daro daro -4 years ago 123
Vb.net Question

Change the date format read from XML file - vb.net

That's my problem: I read the date from a xml file in the

format. Example:

Then I want to write this date in a new file but only in this format:
(that is
, without the time).

What I tried at first it was:

Date_Creation = Date.Parse(noeudEnf.InnerText.ToString)

But then I get the time and I don't want it. So I tried to do this:

Date_Creation = DateTime.ParseExact(Date_Creation, "dd/MM/yyyy", CultureInfo.InvariantCulture)

I thought the problem was the "-" instead of "/" in the xml file. I replaced them but I got the same. I don't know what's next!

Answer Source

First, you need to parse the original to be an instance of the DateTime struct. It just holds the date and time data, not any format:

Date_Creation = Date.Parse(noeudEnf.InnerText.ToString)

Then you can format it as a string:

SomeString = Date_Creation.ToString("dd/MM/yyyy")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download