help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to read in Date from Excel file?


From: PhilipNienhuis
Subject: Re: How to read in Date from Excel file?
Date: Thu, 19 Dec 2013 03:31:30 -0800 (PST)

lisa_octave wrote
> I'm also using Octave 3.6.4
> 
> Yes like using type 2 in datestr() I get the pseudo correct answer by just
> taking the last 2 digits "13" instead of 2013 or 0013. Maybe Octave starts
> with 0000 year?


It depends.

I suppose you use the io package?  If so, in the package directory there's a
subdir doc/ which contains some html files (I still have to learn texinfo
:-) ) about the spreadsheet I/O.   In the file  READ-XLS.html  there's a
stanza on incompatibilities between Matlab and Octave, a.o. about date
values.

I see that you run Octave under Windows. Do you have MS-Excel installed?

Perhaps the below helps you to get some insight:

In Excel 97-2003 .xls files date cells can be distinguished because they
contain a numerical date value (with epoch Jan 1, 1900, w/o taking into
account that 1900 is a leap year so there's the first Excel bug) *AND *they
contain date formatting. If you enter dates from before Excel's epoch (older
than 1-1-1900), Excel stores them as text strings

AFAIK, Matlab returns all spreadsheet date values as text strings.
Octave however, if used with the Windows package and MS-Excel (COM), returns
the date values as numerical values with epoch 1-1-1900, unless the dates
lie outside of Excel's valid date range, in which case it returns the date
values as text strings as well.

Personally I find Octave's behavior much handier, as you normally don't need
to convert date text strings into datenums - Octave already does that for
you. 
In Matlab you'd have to parse date text strings using datenum(), like you
showed in your original post.  But you'd have to make sure that all date
formats are covered. The latter really gets to be a pain if you have Excel
in one language and use spreadsheet files made on another system in another
language.

BTW, if you would use the Java-based spreadsheet interfaces for Octave you'd
find that Octave itranslates date cell contents into Octave/Matlab
"datenums", i.e., numerical date values with epoch 1-1-0, or Jan 1, 0000. 
In that case you wouldn't even have to add  693960  to all Excel dates to
transform them into Octave/Matlab "datenums".

Philip




--
View this message in context: 
http://octave.1599824.n4.nabble.com/How-to-read-in-Date-from-Excel-file-tp4660211p4660230.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]