Excel and Date

Excel and Date

Postby George » Sat Apr 18, 2009 4:09 am

Excel identifies a date with a sequential number indicating the numbers of days lapsed from Enero1, 1900.
For example: 38835 = 4/28/2006 (this is in format MMDDYYYY)
Does exist a Harbour function or someone know how to convert the Excel sequential number in date?

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Excel and Date

Postby nageswaragunupudi » Sat Apr 18, 2009 5:33 am

Harbour ( Clipper ) also stores Dates as numbers in memory. Difference between OLE internal number for dates and clipper numbers is 2415019.

If you read Excel Date ( or from any other OLE source ) as number, you can derive clipper date by adding 2415019 and converting to Date.

Example:
Code: Select all  Expand view

dDate := CToD( "" ) + nExcelDateAsNumber + 2415019
 


I do not know why do you need to all this. We can straight away read date values from Excel. TOleAuto class adds this difference and converts to date.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10482
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Excel and Date

Postby George » Sat Apr 18, 2009 3:14 pm

Thanks nageswaragunupudi for answer my post.
The reason that I need this is that I am reading a CSV file (created from Excel) that has a date field in sequential number format.
I do not have the excel application, therefore, I need to convert the sequential number to date format.

Thanks

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Excel and Date

Postby nageswaragunupudi » Sat Apr 18, 2009 5:26 pm

We can also simplify this code
Code: Select all  Expand view

dDate := STOD( '18991230' ) + nExcelDateAsNumber
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10482
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 33 guests