0

Hi All,

I have an xml which I am reading in a date:

  <DateOfBirthUpdate>
    <DateOfBirth>1951-04-25</DateOfBirth>
  </DateOfBirthUpdate>

My code reads this in as 25/4/1951 00:00:00 but I need to convert it back to it's original format of 1951-04-25 so it can be used in a soap message.

dateOfBirthUpdate.DateOfBirth = Convert.ToDateTime(record.Element("DateOfBirthUpdate").Element("DateOfBirth").Value);

inUpdate.DateOfBirthUpdate = dateOfBirthUpdate;  

I have tried various methods but nothing seems to work.

Many thanks inadvance..

Edited by AquaNut: incorrect spelling

5
Contributors
5
Replies
12
Views
4 Years
Discussion Span
Last Post by ChrisHunter
0

Yup, but that implies I have to convert it from a date format to a string then convert it back.

When the code hits inUpdate.DateOfBirthUpdate = dateOfBirthUpdate, its the dateOfBirthUpdate that has to be in Date type with it converted to yyyy-MM-dd

0

Yup, but that implies I have to convert it from a date format to a string then convert it back.

Nope, you just need to convert it to a string since you already have a valid DateTime object:

string formattedDate = dateOfBirthUpdate.DateOfBirth.ToString("yyyy-MM-dd");    

Edited by deceptikon

1

ddanbe's suggestion works well I use it at the moment, plus if it stays are a DT format when you store it in a string it's easily converted back to DT type.

Edited by ChrisHunter

Votes + Comments
Well said! :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.