Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RW RW is offline
external usenet poster
 
Posts: 49
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop date conversion in Excel when pasting Stephanie Excel Discussion (Misc queries) 4 February 20th 11 07:58 PM
Excel date conversion-UK to US lainy Excel Worksheet Functions 1 February 14th 08 12:49 PM
Turning off Date Conversion in Excel Ken Hutchinson Excel Discussion (Misc queries) 4 July 31st 06 09:09 AM
How to create a date conversion in MS Excel using VBA Sandspirit Excel Programming 2 May 8th 06 05:37 PM
AS400 Date value conversion to Excel D.S.[_3_] Excel Programming 5 December 4th 03 01:02 PM


All times are GMT +1. The time now is 12:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"