Click here to Skip to main content
12,953,491 members (59,517 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I'm converting a datatable into a csv file format. the data contains 3 date columns. What happens is that the dates becomes like this "40939" in the converted csv file. In the data, its "12/15/2012" but after conversion it becomes "40939". Please help me on how to do it in the date format.
Posted 18-Dec-12 14:26pm
Garth J Lancaster 18-Dec-12 22:05pm
you say 'after conversion' - what is the code you are using ? surely what you would be doing is something like

String aDateString = dt.Rows[x][y].ToString("MM/dd/yyyy")

where dt is your datatable, x is a valid row index and y is the column index for a date column defined as datatype typeof(DateTime)

{Whoops - I see you're using VB.NET - you may need to Modify This, but thats the general idea}
Alan Tuscano 19-Dec-12 0:43am
Hi Garth,

I may have found the root of the problem.

the original file is from excel and is converted into datatable. see code below:

Dim sr As New StreamReader(path)

Dim fullFileStr As String = sr.ReadToEnd()



Dim lines As String() = fullFileStr.Split(ControlChars.Lf)

Dim recs As New DataTable()

Dim sArr As String() = lines(0).Split("~"c)

For Each s As String In sArr

recs.Columns.Add(New DataColumn())


'recs.Columns.Add(New DataColumn())

Dim row As DataRow

Dim finalLine As String = ""

For Each line As String In lines

row = recs.NewRow()

finalLine = line.Replace(Convert.ToString(ControlChars.Cr), "")

row.ItemArray = finalLine.Split("~"c)



from this process, the date value is converted in numeric 40939 from its original excel format of 20120131.

How can I convert the date column to date format when converting into datatable using the same code above?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100