Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel date conversion in .NET
When I import an excel date column into my .NET apllication I get a number
instead of a date. When I look at the excel file and examine the cell format, it is set to date, I dont know what is going on here. Some cells are set to general format and they come out fine, I only have a problem with the ones set to date. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel date conversion in .NET
On Nov 5, 1:13 pm, RW wrote:
When I import an excel date column into my .NET apllication I get a number instead of a date. When I look at the excel file and examine the cell format, it is set to date, I dont know what is going on here. Some cells are set to general format and they come out fine, I only have a problem with the ones set to date. Good Morning RW, I have been having the same problem as you have and after two weeks of searching I have found a solution on the http://www.CodeProject.com/. Here is the article you would like to reference: ( http://www.codeproject.com/datetime/... 52#xx258452xx ) My cells actually contained a date with time which in excel format stores it as a double I may have taken the hard way but it works. My sample: string strLocalDate = (((Excel.Range)workSheet.Cells[rowIndex, colIndex0]).Value2.ToString()); double doubleLocalDate = Convert.ToDouble(strLocalDate); int intLocalDate = Convert.ToInt32(doubleLocalDate); int strDD; int strMM; int strYYYY; int l = intLocalDate + 68569 + 2415019; int n = (( 4 * l ) / 146097); l = l - (( 146097 * n + 3 ) / 4); int i = (( 4000 * ( l + 1 ) ) / 1461001); l = l - (( 1461 * i ) / 4) + 31; int j = (( 80 * l ) / 2447); strDD = l - (( 2447 * j ) / 80); l = (j / 11); strMM = j + 2 - ( 12 * l ); strYYYY = 100 * ( n - 49 ) + i + l; Console.WriteLine(strDD + "/" + strMM + "/" + strYYYY); |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Stop date conversion in Excel when pasting | Excel Discussion (Misc queries) | |||
Excel date conversion-UK to US | Excel Worksheet Functions | |||
Turning off Date Conversion in Excel | Excel Discussion (Misc queries) | |||
How to create a date conversion in MS Excel using VBA | Excel Programming | |||
AS400 Date value conversion to Excel | Excel Programming |