So I issue a test query like SELECT * from my table with a start_date column that has a Date data type. This query is then made into a DataTable, after which it's converted to a CSV file. In SSMS, the query returns only the date, as you can see here:

But when I downloaded the converted CSV file, the dates came out like this:

What I want to know is why. Why does the DataTable behave like this? I can't find a direct answer in the documentation of DataTable.
This is on the ASP.NET 4.0 C# platform with SQL Server 2008.
Thanks!
DataTable uses .NET DateTime class and it probably get converted to string with DateTime.ToString() method when CSV is created. That method uses date format from current Thread's Culture settings. You need to use DateTime.ToString(string format) overload when creating CSV to specify desired format of DateTime.
Here's general description of culture-specific DateTime formatting on .NET platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With