Kate
Kate

Reputation: 372

Divide datetime from xml

I have xml file and I load data from him...One of data is datetime in one: 2013-09-06 11:49:10 My load xml:

XDocument doc = XDocument.Load((backup) + (file));
var TIME = doc.Descendants("TIME");

And I need divide datetime on Date and Time. Have you any idea? Because after that I give the date into sql and time into other column in sql.

Upvotes: 0

Views: 68

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503280

Well given any particular element, you can cast to DateTime:

var timeElement = doc.Descendants("TIME").First();
var dateTime = (DateTime) timeElement;

You can then use the Date and TimeOfDay properties to split the date from the time of day:

DateTime date = dateTime.Date;
TimeSpan time = dateTime.TimeOfDay;

Upvotes: 3

Related Questions