daro
daro

Reputation: 313

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

That's my problem: I read the date from a xml file in the yyyy-mm-ddThh:mm:ss format. Example: <Date_Creation>2015-06-10T08:56:44</Date_Creation>

Then I want to write this date in a new file but only in this format: 06/10/2015 (that is MM/dd/yyy, 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!

Upvotes: 0

Views: 971

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 156948

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")

Upvotes: 1

Related Questions