Experts, please help…
I have a datatable where I load in data from a SQL Server database with tens of thousands of records and I have a procedure which outputs the entire datatable to a delimited text file.
My procedure to do so has code along the following lines:
For Each dtRow As DataRow In dtToWrite.Rows
File.WriteLine(String.Join(strDelimitter, dtRow.ItemArray.Select(Function(Field) Field.ToString)))
Next
Basically creating a delimited string from each datarow from my datatable using the string.join function.
Now, my problem is that I am pulling in Date values from SQL Server and so the final output has, for the date columns, values that look like:
“9/30/2012 12:00:00 AM”
Whereas I only want it to show:
“9/30/2012”
What is the best way to get my data to output ONLY the date portion from the datatable?
Thanks!
In your SQL Query, you could convert the DateTime to a preformatted string. Like this:
For more date formats, check out the MSDN list of formats