XSLT Transformation DateTime

G

Guest

I have a DataSet that has several DateTime columns. I retrieve the XML from
the DataSet by using its DataSet.GetXML method. This XML gets loaded into an
XPathDocument. I've also created a basic style sheet, which I'm applying to
the XML. I then transform the XML into a CSV file, using the XslTranform
class.

This causes the DateTime fileds to appear in a format such as this one:
2005-04-07T17:00:00.0000000-05:00. This representation of the DateTime value
is unformattable in Excel. I would like to dispaly the DateTime value as
"mm/dd/yy hh:mm:ss t" format, so that the date shown above would appear as
"04/07/2005 12:00:00 AM". Is there a way to convert the DateTime value to a
palpable format during the Tranformation?

Thanks.
 
K

Kevin Yu [MSFT]

Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to transform the DataSet to a
CSV file. Also, you need the DateTime data to be in the format you require.
If there is any misunderstanding, please feel free to let me know.

If you need to convert it into a CSV, I don't think using XSLT on this is a
good idea. Because if we need to convert DateTime column into your own
format, we have to the conversion manually. We have to parse the string and
reconstructure it. It's quite complex in XSL.

So my suggestion is to write each cell to a CSV file directly using C#
code. Here is an example:

foreach(DataRow dr in ds.Tables[0].Rows)
{
string s = dr[0].ToString() + ", ";
DateTime dt = (DateTime)dr["DateTimeCol"];
s += dt.ToShortTimeString();
streamWriter.WriteLine(s);
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top