Q:

Convert xmlWriter.WriteElementString value to date and time

I am using c# to  write this value that is coming from SQL into an XML file. It is datatype datetime in the SQL table.
xmlWriter.WriteElementString("DDATE", reader[7].ToString());

How do I convert it to date and time in this format?
2011-11-21T00:00:00 
Keep on getting error: cannot convert sytem.datetime to string when I try:
DateTime.ParseExact

A:

You can use reader.GetDateTime() to get the DateTime from the database.  Then, since WriteElementString takes string arguments just call .ToString():
xmlWriter.WriteElementString("DDATE", reader.GetDateTime(7).ToString("yyyy-MM-ddTHH:mm:ss"));

If you always want the time component to be 00:00:00 just use dateTime.Date.
reader.GetDateTime(7).Date.ToString("yyyy-MM-ddTHH:mm:ss"))

