Newbie on C#

0 Ryuop Riu · April 15, 2015
Hi,

Trying to learn C#. I trying to put a string date into datetimepicker from an xml file. Here is the xml snippet:


  <schedule start="2015/04/14-20:02:32" end="2015/04/14-20:02:32">

and here is my code:

dateTimePicker1.Value = (xDoc.SelectSingleNode("schedule/@start").InnerText); This is not working.

I can successfully save to the xml file with the right format:

string start = dateTimePicker1.Value.ToString("yyyy'/'MM'/'dd-HH:mm:ss");

xDoc.SelectSingleNode("schedule/@start").InnerText = start.ToString();

xDoc.Save(path);

Can somebody please guide me to the right code to insert the date to datetimepicker..

Regards
Ryuop

Post a Reply

Replies

Oldest  Newest  Rating
0 Ryuop Riu · April 16, 2015
Nevermind, I did solve it myself. Here is how:

string start = (xDoc.SelectSingleNode("schedule/@start").InnerText);
             

              DateTime MyDateTime;
              MyDateTime = new DateTime();
              MyDateTime = DateTime.ParseExact(start, "yyyy'/'MM'/'dd-HH:mm:ss", null);
              
              dateTimePicker1.Value = MyDateTime;
              
  • 1

C#

107,055 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators